Wednesday 20 November 2013

Java: notes on IBM's multitenant v8 beta JVM

I thought I'd take a look at IBM's Java 8 beta multitenancy support. This is a mechanism for sharing runtime resources across Java virtual machine instances. See developerWorks' "Introduction to Java multitenancy."

I installed ibm-java-sdk-ea-8.0-0.0-x86_64-archive3.bin on Linux using a CentOS-6.4-x86_64-LiveCD.iso based host.

-Xmt mode

public class HelloTenant {
  public static void main(String[] args) {
    System.out.println("Hello, Tenant!");
  }
}

Compiling and invoking the above program:

$ javac HelloTenant.java
$ java -Xmt HelloTenant

The first thing you notice when running the above program is that System.out doesn't write to the console. Redirecting output to a file doesn't help.

The second thing you notice is that the process doesn't stop immediately after execution. This seems to be a side-effect of the first thing.

This code executes as expected:

import java.io.*;

public class HelloFile {
  public static void main(String[] args) throws IOException {
    try(PrintStream out = new PrintStream("hello.txt")) {
      out.println("Hello, Tenant!");
    }
  }
}

Documented limitations

Multitenancy cannot be applied arbitrarily to Java applications. There are documented limitations.

Beware:

  • Native libraries (including GUIs like SWT)
  • Debuggers and profilers

Processes

public class Sleeper {
  public static void main(String[] args) throws InterruptedException {
    int minutes = Integer.parseInt(args[0]);
    Thread.sleep(minutes*60*60*1000);
  }
}
When a tenant is launched, the JVM launcher either locates the existing shared JVM daemon (javad) or starts it if necessary...

When you launch a few instances you still get a few processes waiting around in user space for the daemon to finish processing:

$ javac Sleeper.java
$ java -Xmt Sleeper 2 &
[1] 3007
$ java -Xmt Sleeper 2 &
[2] 3010
$ java -Xmt Sleeper 2 &
[3] 3013
$ ps -al | grep java
0 S   500  3007  2787  0  80   0 - 29561 futex_ pts/0    00:00:00 java
0 S   500  3010  2787  0  80   0 - 29515 futex_ pts/0    00:00:00 java
0 S   500  3013  2787  0  80   0 - 29515 futex_ pts/0    00:00:00 java

It isn't clear to me what is going on in these processes. pmap seems to report the same RAM usage for each of these processes regardless of program (~100Mb) but I don't know what I'm really measuring.

End notes

Concurrent JVM instances:

Table 1. Maximum number of concurrent applications
ApplicationDescriptionImprovement with multitenant JVM
Hello WorldPrint "HelloWorld" and then sleep4.2X to 4.9X
JettyStart Jetty and wait for requests1.9X
TomcatStart Tomcat and wait for requests2.1X
JRubyStart JRuby and wait for requests1.2X to 2.1X

Instance control:

The multitenant JVM provides controls that can be configured to limit a tenant's ability to misbehave and use resources in a way that affects other tenants. Values that can be controlled include:
  • Processor time
  • Heap size
  • Thread count
  • File I/O: read bandwidth, write bandwidth
  • Socket I/O: read bandwidth, write bandwidth

IBM's multitenancy JVM support is aimed at selling cloud services. While these use cases are interesting I'm interested to see if this sort of tech makes it into Java EE application servers like WebSphere. The ability to fine-tune individual applications within an application server might prove useful for fine-tuning performance, application isolation and deployment.

No comments:

Post a Comment

All comments are moderated