core icon indicating copy to clipboard operation
core copied to clipboard

Remote URL access should be run in a threadpool

Open wezell opened this issue 2 years ago • 3 comments

Customers often use the $json or $import tools to pull content from 3rd party APIs and display it on their pages. The issue with this is that if the remote API/content is down or becomes non- accessible, then tomcat threads back up and instances can crash - as there are no tomcat connector threads available to service incoming requests.

In order to avoid this we should run all calls using the CircuitBreakerURL in a configurable threadpool of, say 100, threads and then reject any subsequent requests. This would mean that if a remote url is down on high traffic pages, then only 100 tomcat connector threads would be hung up at any one time. By default we run tomcat with 600 connector threads so by limiting the number of remote calls to 100 threads would still allow 500 threads to still be available for other requests.

wezell avatar Jul 06 '22 14:07 wezell

PR: #22571

nollymar avatar Aug 16 '22 22:08 nollymar

  1. I would recommend to set this config

export DOT_CIRCUIT_BREAKER_MAX_CONN_TOTAL=3

This will create a pool with just 3 connections.

  1. Then start the local instance

  2. Create a Page that make a request with the json tool (velocity viewtool) to some url, such as google or dotcms.com.

  3. Make a massive call to that page, for instance:

seq 1 800 | xargs -n1 -P10 curl -X GET http://localhost:8080/mytest

But you can use your favorite stress tool


Should see how some requests are broken and some are success, it is b/c the code limits the quantity of calls to the json tool, if it is more than 3 (in this case) will throw an error.

jdotcms avatar Aug 16 '22 22:08 jdotcms

Internal QA: Passed

nollymar avatar Sep 01 '22 21:09 nollymar

Fixed, tested following the provided steps and adding the follow code to the page $json.fetch('http://www.google.com')

Here is the log after do the simultaneous request https://gist.github.com/bryanboza/43dc4b59249a66d280c6eca1a9052f74

Tested on release-22.10 // Docker // FF

bryanboza avatar Oct 11 '22 22:10 bryanboza