Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reactphp process status statistic (idle, worked, etc)

I starting using http://reactphp.org/ for handle HTTP request.

I run multiple react workers that run on different ports and then use Nginx as load balancing to handle requests. Like this

upstream backend  {
    server 127.0.0.1:13300;
    server 127.0.0.1:13301;
    .....
}

All works well as expected.

The question is how to get a statistic of reactphp process status. How many processes currently on idle state (waiting for new request), how many process is work under request, etc.

Is there existing workaround?

Or idea how to handle process statistic by hand.

Example - locking write to some cache process status. When is start request process - increase number of handled processes, when finish request - increase number of idle processes.

like image 515
Oleksandr Otchenashev Avatar asked May 05 '15 07:05

Oleksandr Otchenashev


1 Answers

The last time I had a set of worker threads I set up some tables in a MySQL DB.

workers was where each thread registered a row (giving it an ID). The thread would lock it's row and maintain the status column.

There was also an instructions stack. If the worker saw it's ID and the text "exit" it would close up and exit. Last thing would be to delete it's row. Setting status to exited also would have worked.

I also made a status report and admin page where I could issue commands and set up tasks for my worker threads.

This would then allow you to see what each thread was doing and get a count of idle threads.

Idle threads:

SELECT count(id) AS threads WHERE status='idle';

Thread status count:

SELECT status, count(id) AS threads GROUP BY status;
like image 137
Matthew Brown aka Lord Matt Avatar answered Sep 21 '22 02:09

Matthew Brown aka Lord Matt