xa-data-source add \ --name=MyDS \ --driver-name=h2 \ --jndi-name=java:jboss/datasources/MyDS \ --user-name=sa \ --password=sa \ --xa-datasource-properties={ \ "URL" => "jdbc:h2:/tmp/localtxtest;AUTO_SERVER=TRUE"}
JDBC chunk oriented processing with jberet.local-tx
TweetPosted on Saturday Feb 21, 2015 at 11:40PM in Technology
As following URL said, in my understanding, each open, read, write and close of every JDBC resources (Connection, Statement and ResultSet) needs to be in it’s own transaction.
There are open
and close
methods in ItemReader
and ItemWriter
interface. these methods looks like good to create and dispose JDBC resources such as Connection
, Statement
and ResultSet
but we can’t go that way due to the JSR352 spec. before invocation of these methods, the framework starts a transaction, then commits a transaction after invocation finished. according to preceding URL said, these resources become unusable at readItem
and writeItems
method because these resources were created in another transaction.
It’s terrible to do open a cursor again and again at start of every chunk processing. to overcome this problem, JBeret supplied an implementation specific parameter named jberet.local-tx
. so I created a sample batch project to test that parameter. my test was done with WildFly 8.2.0.Final.
How the batch works
Entire project can be obtained from my GitHub repository. the batch has 2 steps as follows:
-
prepare
: createsSRC
andDEST
table, and insert 100 rows intoSRC
table. refer source of Batchlet for details. -
test
: loads data fromSRC
table, then simply writes data intoDEST
table as is using chunk oriented processing. this step has a propertyjberet.local-tx
withtrue
value.MyItemReader
creates and disposes JDBC resources inopen
andclose
method. refer source of MyItemReader and MyItemWriter for details.
How to run the batch
-
Define a H2 DataSource
-
Deploy the project
-
Access http://localhost:8080/localtxtest-1.0-SNAPSHOT/ to launch the batch through the Servlet which mapped at
/
-
Look your database to the check batch works expectedly
Notes
Actually, the problem ARJUNA016087
warning is disappeared in latest WildFly 8.2.0.Final without using jberet.local-tx
. but I don’t know whether it is intended to fix or simply by chance still. I’ll keep looking further of this discussion.
Derby database backup script
TweetPosted on Friday Feb 20, 2015 at 02:49PM in Technology
As Roller, and a virtual machine on VMware Fusion, I wrote an another Ant script which backups an Apache Derby database to automate backup of data of my Apache James server. the script has easy purge function as a target named purge
too. intended environment is as follows:
-
Linux server
-
Accepts connection via ssh
-
Has executable
ij
command which is simple CLI JDBC frontend program shipped with Derby -
Requires Derby instance to listen a port
It works as follows:
-
Invoke
SYSCS_UTIL.SYSCS_FREEZE_DATABASE()
withij
to freeze the database -
Create a tarball of the database
-
Invoke
SYSCS_UTIL.SYSCS_UNFREEZE_DATABASE()
withij
to unfreeze the database -
Download the tarball
-
Delete the tarball
A bad thing is that due to lack of streaming download in sshexec task, it needs extra free space on the server. the script can be obtained from my GitHub repository.
Memory usage tuning of Java8 on Linux
TweetPosted on Thursday Feb 19, 2015 at 06:20PM in Technology
I have a WildFly and a Apache James server instance on Linux based VPS which have 1GB RAM. these days they allocates large swap area while they only used fewer than 1GB for actual memory consumption. performance is not bad for just serving without any administrative operations, but some operation tend to slow due to large swap size so I configured some to reduce swap size.
Environment
-
CentOS 6.5
-
Oracle JDK8u31
Before
top - 21:06:05 up 118 days, 19:07, 1 user, load average: 0.01, 0.02, 0.00 Tasks: 123 total, 1 running, 122 sleeping, 0 stopped, 0 zombie Cpu(s): 0.5%us, 0.2%sy, 0.0%ni, 99.3%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st Mem: 1020224k total, 947560k used, 72664k free, 5692k buffers Swap: 2097144k total, 500732k used, 1596412k free, 65308k cached PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ SWAP COMMAND 29457 wildfly 20 0 3183m 438m 6152 S 0.3 44.0 41:27.36 355m java 19826 james 20 0 2725m 281m 6788 S 1.0 28.3 28:28.08 39m java ...
Configure JVM params
Set following JVM params to James:
-XX:ReservedCodeCacheSize=100m -XX:MaxMetaspaceSize=128m -XX:CompressedClassSpaceSize=128m
Set following to wildfly as well:
-XX:ReservedCodeCacheSize=100m -XX:MaxMetaspaceSize=256m -XX:CompressedClassSpaceSize=128m
After
These parameters reduced swap size as follows:
top - 19:33:09 up 119 days, 17:34, 3 users, load average: 0.41, 0.24, 0.10 Tasks: 130 total, 1 running, 129 sleeping, 0 stopped, 0 zombie Cpu(s): 0.3%us, 0.3%sy, 0.0%ni, 99.3%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st Mem: 1020224k total, 924232k used, 95992k free, 8400k buffers Swap: 2097144k total, 407972k used, 1689172k free, 90320k cached PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ SWAP COMMAND 30181 wildfly 20 0 2141m 405m 6308 S 0.0 40.7 5:11.08 272m java 29949 james 20 0 1677m 249m 6720 S 0.7 25.0 5:52.41 46m java
UPDATE: Now swap size grown as almost before adding configuration so sadly now I’m not sure whether it works or not.
Setting swappiness
vm.swappiness
defines how often the swap file is used. setting lower value means lower swap size but it doesn’t simply mean better performance. you can adjust it via executing following command to apply instantly:
sudo sysctl vm.swappiness=1
Add following definition to /etc/sysctl.conf
to set it as persistent one:
vm.swappiness = 1
Following discussions may be useful:
Importing entries into Roller
TweetPosted on Thursday Feb 19, 2015 at 11:54AM in Technology
Recently I migrated old articles that wrote within hand made blog (?) engine to Roller. there’s a useful Groovy script that placed in source distribution of Roller. I referenced that script and created a standalone Java program which imports entries that saved as RSS 2.0 XML. the program is intended to use with WordPress WXR file but I’ve never used it with real WXR file which WordPress produced because I don’t have any WordPress instances for my own. I used it for a XML file which produced by Rome and before import I added some tweak by hand.
I think it’s harder to use without any modification but it may be helpful for someone wants to import entries with API for Roller, so I pushed the program into GitHub.
Tags: roller
What are lookahead / lookbehind of regex?
TweetPosted on Sunday Feb 15, 2015 at 10:04AM in Technology
I’m learning regex with Mastering Regular Expressions, 3rd Edition. it’s interesting because long time I didn’t understand lookahead / lookbehind correctly. so I leave some examples for better understanding. tests were ran against jEdit 5.2.0 on Oracle Java 1.8.0_31.
Given string
(1) http://blog1.example.com/roller/ (2) http://blog2.example.com/mt/ (3) http://blog3.example.com/wordpress/
Positive lookahead
Positive lookahead ensures that the matching has following fragment which matches to given regex inside parenthesis. example\.com(?=/roller/)
matches against only (1)
.
Negative lookahead
Negative lookahead simply reverses that condition. example\.com(?!/roller/)
matches against (2) and (3)
.
Positive lookbehind
Positive lookbehind means that the matching has the preceding fragment which matches to given regex inside parenthesis. (?<=blog1\.)example\.com
matches against only (1)
.
Negative lookbehind
Negative lookbehind simply reverses that condition. (?<!blog1\.)example\.com
matches against (2) and (3)
.
Tags: regex