I am trying to recursively iterate over a long json payload in apigee edge JavaScript policy. For its execution apigee is taking 5x times more execution time than same javaScript function when I am trying on my local in Chrome browser . I would like to understand the possible cause of it, and remedies for it.
Picture 1st = time take by apigee edge javaScript policy
Picture 2nd = time taken by local JavaScript code
Solved! Go to Solution.
The JS policy in Apigee runs in a Rhino JS interpreter. It's not JIT compiled and optimized like the v8 engine in Chrome. Logic might take longer running in an Apigee JS callout. There is no "remedy". This is just how it works.
If you have expensive computation, it shouldn't be running within the context of an Apigee API Proxy. Move that logic into a separately managed application, maybe using Cloud Run, Cloud Functions, GKE, App Engine, or whatever. That way it can use v8, and a modern nodejs, and benefit from all the perf enhancements available.
BTW, Your two images don't seem to show a 5x ratio. One of them seems to indicate the computation takes ~48 seconds, the other ~52 seconds. But I believe you that "things run more slowly in a JS callout running in Apigee."