0

I have written a small web server that I wrote in node.js that uses node-java to invoke a commercial product API. I originally used (mostly all) Async (non-Sync) calls to invoke that API, as shown here:

Critique for node.js+node-java application that interfaces with a COTs product?

but I noticed some kind of puzzling problems last week with the API (the Jmeter test would hang for awhile at the end of the test and the commercial product would take awhile to process the last several requests) while testing, and I've been trying to figure those out.

So, then, today, I decided to try to modify the node.js+node-java code to use only Sync calls to invoke the API.

I changed this part of the code:

// The following also now works, and this invokes the PDP in Asynch mode!!
var x = java.callStaticMethod("OesPdp", "DoAtzRequest", "xxx", function (err, data) {
        if (err) {
                console.log("In handleRequest: err = [" + err + "}");
                return;
                }
        console.log("In handleRequest: In callback-good-path, data=[" + data + "]");

        // NOTE that the 'data' is what is being returned from the DoAtzRequest method of the OesPdp Object!!
        response.end("THE DATA IS: [" + data + "]");
        return "AAAAAAAAAAAAAAAA";
        } // end CALLBACK function
);

by replacing it with this (i.e., I'd call the API method using Sync call):

// The following WORKS, but it invokes/runs the PDP in Sync mode...
var x = java.callStaticMethodSync("OesPdp", "DoAtzRequest", "xxx");

console.log("x=[" + x + "]");
console.log("THE DATA that was returned from the OES PDP, 'x', IS: [" + x + "]");
response.end("THE DATA that was returned from the OES PDP, 'x', IS: [" + x + "]");

I'm using Jmeter to do the load testing, and my base test runs 10 simultaneous threads continuously, and previously when I was using the Async calls, I was assuming that the app was processing 10 requests "simultaneously", so I thought that when I switched all the method calls to Sync calls, that the web server app would be processing all requests sequentially and that I'd get really worse/bad results.

But, to my surprise, after I switched the method calls to Sync calls, my Jmeter test results were way, way better, and I went from processing ~9000 requests in 60 seconds test run to ~35K requests in 60 seconds :(!!

Additionally, the problems that I kind of alluded to earlier, don't occur when I used the new code with the Sync calls!

I'm glad that it is working better using the Sync method call, but I am really puzzled/confused now about why the load test results would be BETTER and also, SO MUCH BETTER, when I use the Sync method call, than when I was using the Async method calls??

Can anyone explain why this is the case?

Thanks, Jim

P.S. One thing I should mention is that in both the old code and the new code, the call to instantiate the API Java object was a Sync one (i.e., using "java.newInstanceSync"):

var MyOesPdpClass = java.newInstanceSync('OesPdp');
Community
  • 1
  • 1
user555303
  • 1,146
  • 3
  • 20
  • 44
  • Well you're going through the whole effort to marshal days twice instead of once. Considering that the operation is obviously quite fast it can't do long IO or anything else blocking. Generally if the API itself doesn't provide async functionality grafting it on afterwards can not provide performance benefits - the only thing you do if cause additional overhead but the actual function call still runs synchronously. – Voo Oct 04 '16 at 06:38
  • @Voo - Thanks. A couple of things: (a) that "OesPdp" class is a small class that I wrote to wrap the actual commercial product API, so it's Java that I implemented myself and (b) I kept reading that with node.js that I should always use async and callbacks? Since the class is my Java code, is there something that I could've done in my code to make it "amenable" to being called async from Node.js? BTW, I added code to track the requests, from the Node.js through the wrapper class, and everything is purely sequential now. It's amazing that it's faster though (actually WAY, WAY faster!)!! – user555303 Oct 04 '16 at 12:39

0 Answers0