PhantomJS with integrated web server uses only one processor

I have a problem using PhantomJS with a web server module in a multi-threaded way with concurrent requests.
I am using PhantomJS 2.0 to create server-side highstock charts with Java, as explained here (and the code here ). It works well, and when testing graphs of several sizes, I got results that are pretty consistent, about 0.4 seconds, to create a graph.

The code I linked to was originally published by the highcharts team and is also used on the export server http://export.highcharts.com/ . To support concurrent requests, it stores a pool of generated PhantomJS processes, and basically its model is a single instance of phantomjs for a simultaneous request.

I saw that the web server module supports up to 10 concurrent requests (explained here), so I thought I could use this to save fewer PhantomJS processes in my pool. However, when I tried to use more threads, I experienced linear slowdown, as if PhantomJS was using only one processor. This slowdown is displayed as follows (for one instance of PhantomJS):

1 client thread, average request time 0.44 seconds.
2 client threads, average request time 0.76 seconds.
4 client threads, average request time 1.5 seconds.

Is this a known limitation of PhantomJS? Is there any way around this?

(the question is also posted here )

+5
source share
1 answer

Is this a known limitation of PhantomJS?

Yes, this is an expected limitation, because PhantomJS uses the same WebKit mechanism for everything, and since JavaScript is single-threaded, it actually means that each request will be processed one after the other (possibly with a lock), but never at the same time . The average total time will increase linearly with each client.

The documentation says:

There is currently a limit of 10 concurrent requests; any other requests will be queued.

There is a difference between the concepts of parallel and parallel queries. In parallel, it simply means that tasks end non-deterministically. This does not mean that the instructions with which tasks are performed are executed in parallel on different (virtual) cores.

Is there any way around this?

Other than starting server tasks using child_process, no . The way JavaScript supports multithreading is the use of web workers, but the worker is isolated and does not have access to require and therefore cannot create pages for work.

+5
source

Source: https://habr.com/ru/post/1216021/


All Articles