Bulk Requests

Bulk-Requests

In order to monitor Java application servers, a multitude of parameters can be observed. Memory and thread consumption, database connection pool utilisation, HTTP request response for various web application are examples for valuable metrics to monitor. Typically, 10-20 monitored attributes are a good setup for a single JEE server.

With the traditional approach using JSR-160 JMX connectors, a connection is opened, and for each attribute queried a separate RMI (or optional JMXMP) request needs to be send to the server resulting in several client-server turnarounds. Wouldn't it be nice to use a single request for querying all those parameters ?

With Jolokia's bulk requests this is a piece of cake. A single HTTP POST request can carry a list of JSON request objects, which are dispatched by the Jolokia agent on the server side into multiple local JMX calls. The results are collected and returned as list of JSON response objects. In case of an exception when executing the JMX call, the error is propragated as part of the response without influencing the other results.

Example

Let's have a look at an example. Jolokias client libraries (currently available for JavaScript, Java and Perl) make the usage of bulk request easy by providing an extra layer of abstraction:

  J4pClient j4pClient = new J4pClient("http://localhost:8080/jolokia/");
  J4pRequest req1 = new J4pExecRequest("java.lang:type=Memory","gc");
  J4pRequest req2 = new J4pReadRequest("java.lang:type=Memory","HeapMemoryUsage");
  List<J4pResponse<J4pRequest>> responses = j4pClient.execute(req1,req2);
  Map memVals = responses.get(1).getValue();
  System.out.println("Memory used: " + memVals.get("used"));

This gets translated in the following JSON request, which is transmitted to the agent via an HTTP POST request (the URL has been set up in the j4pClient object above):

   [{ "operation":"gc",
      "mbean":"java.lang:type=Memory",
      "type":"EXEC" 
    },
    {
      "mbean":"java.lang:type=Memory",
      "attribute":"HeapMemoryUsage",
      "type":"READ"
    }]

The answer returned is also represented in JSON and looks like this:

   [{ "timestamp":1285442161,
      "status":200,
      "request": { "mbean":"java.lang:type=Memory",
                    "operation":"gc",
                    "type":"exec" },
      "value":null
     },
     {
      "timestamp":1285442161,
      "status":200,
      "request": { "mbean":"java.lang:type=Memory",
                   "attribute":"HeapMemoryUsage",
                   "type":"read" },
      "value": {"max":"129957888",
                "committed":"85000192",
                "init":"0",
                "used":"3660720" }
     }]

Another example how bulk requests can be used is the Nagios Plugin check_jmx4perl, which uses bulk requests for its multi check features, which allows for a single Nagios check monitor as many JMX attributes and operations as required.

Next