M
M
Mikhail2021-11-19 06:04:47
Node.js
Mikhail, 2021-11-19 06:04:47

How to create multithread via docker?

Here's an example. The server has php and nodejs
PHP sends a command to a node like
node mydir/script.js https://example.com
Puppeteer is installed on the node (this is a web browser type driver) It normally cannot be run several times at the same time in one node.

And the node returns data to PHP
Everything works well BUT!

PHP can send at least 100 links to a node per second. And the node processes 1 link per second (

So I thought about how to make several threads. It can create 20 dockers with a node on the server.
But how can I do it with a docker. I
slipped the idea to make 20 dockers on 20 different ports

And then send 20 pieces from PHP.Maybe there are already run-in methods?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Shitskov, 2021-11-19
@Zarom

If you are limited to bare docker as a runtime, then you can try using scale in docker-compose for example, specifying a range of ports

services:
  web:
    image: "puppeteer" 
    ports:
       - "8081-8099:8080"
    scale: 10

If the task is solved correctly, then you need to use queues in Redis / Rabiit / NATS / other MQs.
The PHP script should push tasks into the queue, and 10 containers with a node should pick up tasks from the queue, process and return the result to the queue with the results (if the result is small). So you can guarantee that all services will be busy evenly under load and will not choke.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question