- Март 14 – Встреча пользователей Oracle Coherence – один из создателей Coherence удалённо выступит для нас с докладом.
- Март 28 – И снова деплоймент – обсудим проблему на примере развёртывания OpenStack.
- Апрель 18 – Магия виртуальных машин – Python, Erlang, Ruby, JavaScript - что мы знаем про виртуальные машины для этих языков?
- Май 16 – Сборка мусора в Java - возвращаемся к вечной теме, как изменилось положение дел за последний год? Так же будет организована видео трансляция. Дата предварительная.
Tuesday, March 12, 2013
Upcomming tech meetups in Moscow
Friday, February 1, 2013
How to simulate Coherence node failure in JUnit test
Recently, I was working on renewed version of Coherence data loss listener. New version provides simple utility to attach partition loader to any cache. Such partition loader is guaranteed to be called for every partition of newly created cache or after partition has been lost. Unlike CacheStore, partition loader will be called on the node there it has been added. This way you could have dedicated set loader processes, which are not involved at storing a data. Also it is guaranties that
But let’s get back to a topic of post. I’m actively using JUnit and my test-utils library to automate testing of my Coherence stuff. Test-utils is using class loader isolation to run multiple Coherence nodes in single JVM.
But, unlike many other tests, here I need to test disaster case. Coherence should think that one of its nodes has died. Normally, I’m using CacheFactory.shutdown() to kill virtualized Coherence node, but this way it would be a graceful shutdown.
For data loss listener, I really want to test disaster case.
How Coherence track node liveness?
Naïve approach using timeout is not working well with data grid prioritizing resilience and performance such as Coherence.
What is problem with timeout?
If you let it be too short, there will be too many false positives making grid unstable (JVM may do a GC, OS may start swapping, etc).
If you let it be too long, time of recovery from disaster would be too long.
How this can be improved? Let’s see that kind of disaster could possibly happen with your cluster:
Death of process could be easily tracked if you keep open TCP connection open. OS will close all TCP connections for dead process, so you could make very good assumption that remote process is dead.
Coherence is using so called TCP ring for that purpose. Each cluster node keeps two open TCP connections to other cluster nodes (forming a ring). If cluster detects that both TCP connections have been closed, it has very good reason to disconnect node right now and start recovery procedure.
In case of server/network failure, TCP connection will not be closed immediately. In addition to TCP ring, Coherence is using IP monitor to track reachability of IP addresses. If IP address cannot be reached by rest of nodes, cluster will not hesitate to disconnect all nodes from that IP.
This two tricks allow Coherence to detect real failure very fast, yet to be very tolerant to long GC pauses and other non fatal slowdowns.
Steps to kill node in JUnit test
In JUnit test all nodes in cluster are sharing same JVM. I cannot really kill a process. To simulate node death, I’m calling Thread.suspend() on all threads related to victim node (a feature of test-utils). This is making node totally unresponsive.
Two mechanisms above should be turned off in Coherence operational configuration. Disconnect timeout also should be set to smaller value (otherwise each test will take too long).
That is it, now I can test disaster cases for Coherence using JUnit.
Below is snippet of actual test:
Here is a link to full java file in SVN.
Monday, January 28, 2013
Remote code execution in Java made trivial
SSH offers a very convenient way to execute shell scripts remotely. Code like
ssh myserver.acme.com
<< EOC
cd $APP_HOME
./start_my_stuff.sh
EOC
are fairly easy to write and read.
But while remote execution itself is easy, writing actual distributed code is total mess.
I’m a Java
guy. I wish, I could run Java code remotely as easy as I can do it with shell.
And now, finally, I can.
And that snippet will work for you too, only two requirements are:
That is it, there is no need to install anything special to target servers.
You can find more details in tutorial at GridKit site.
How it work?
A lot of black magic is happening behind the scene. In particular:
By despite
all that internal complexity, it just works. I’m using it to run agents on
Linux and Solaris. I was using that stuff on Amazon EC2 and I cloud have master
process running on my Windows desktop while slave scattered across Unixes.
It was long road. A lot of issues such as firewalls, bugs in JSch (java SSH client),
subtle SSH limitation, etc has been solved along that path.
But now, I believe, it will “just work” for you too.
Java vs shell
But what is the need for such library in a first place? Below are just few of my reasons:
Remotting is just a remotting
Ability to effortlessly run remote java code is not much by itself. But it enables you to reach new levels of day-to-day automation (which was prohibitively expensive before).
But that would be topic for another post.
