"If performance is a concern for custom functionality, use Java where possible." (?)

mail-2
Participant IV

"If performance is a concern for custom functionality, use Java where possible."

https://docs.apigee.com/api-platform/samples/cookbook/programming-api-proxies-javascript

I find this statement to be really weird - since when is performance negotiable? Especially with APIs where latency is always to be kept as low as possible.

Shouldn't the recommended language also be the most performant?

This seems like a significant design flaw to me.

Solved Solved
0 5 288
1 ACCEPTED SOLUTION

Shouldn't the recommended language also be the most performant?

In a perfect world, the cheapest automobile would be the most efficient, the fastest, the most comfortable, and would also be able to haul the most cargo. We know that's not true. In engineering disciplines, there are tradeoffs.

The easiest-to-drive car may not be the one that goes fastest. The most comfortable one may not be able to haul much cargo.

Depending on whether you value ease of use or top speed, you may choose car #1 or car #2.

And the same is true with extensions in Apigee. The easiest to use is (for most people) JavaScript. It is not the most efficient. If you want ease of use, JavaScript. If you want optimal performance, use Java. If you want a balance, then ... you'll have to make a judgment call.

good luck!

View solution in original post

5 REPLIES 5

Shouldn't the recommended language also be the most performant?

In a perfect world, the cheapest automobile would be the most efficient, the fastest, the most comfortable, and would also be able to haul the most cargo. We know that's not true. In engineering disciplines, there are tradeoffs.

The easiest-to-drive car may not be the one that goes fastest. The most comfortable one may not be able to haul much cargo.

Depending on whether you value ease of use or top speed, you may choose car #1 or car #2.

And the same is true with extensions in Apigee. The easiest to use is (for most people) JavaScript. It is not the most efficient. If you want ease of use, JavaScript. If you want optimal performance, use Java. If you want a balance, then ... you'll have to make a judgment call.

good luck!

You definitely have a point there.

Do you have metrics to share on the average performance difference?

How is the JavaScript integrated into Apigee internally?

Is Apigee running on JVM?

Apigee runs on a JVM, and the JavaScript policies in Apigee run within the JVM under Rhino.

The efficiency advantage of Java over JavaScript for doing things like crypto or digital signatures... is significant. The difference for getting and setting variables and manipulating strings... is not that significant.

For average performance difference, it depends on what you are trying to do in your code.

Simply setting values for couple of variables v/s playing around with large request/response payloads.

I will give couple of examples, although I don't have exact benchmarks for JavaScript v/s Java.

1. I was using JavaScript to generate the log message and store it in a variable for Message Logging Policy. JavaScript was doing fairly good, taking about 5-7 ms, with occasionally taking 20 ms. This policy was in flowhook (so basically executing for each single transaction).

It was all good until the load was about 500 TPS.

2. We needed more information to be logged, updated the JavaScript policy (very convenient), but it started taking about 10-12 ms, at the same time, load increased to about 900 TPS.

3. Next round was to improve this performance, whereas until now it was all about convenience.

I converted JS policy to Java, while still enriching our logs with more information. Java takes around 1-3 ms, with occasional 5-7 ms at 2500+ TPS (of course more infrastructure was added to support additional load).

Remember, Apigee is Java based and JavaScript runs in an engine(inside), so pretty much everything has to be marshalled into JS by Message Processor before it can be modified inside JS context.

That's the cost and Dino already answered it.

Hope this helps!

Very interesting - Thanks for sharing your experience!