A
A
allebin2018-07-28 17:23:51
Nginx
allebin, 2018-07-28 17:23:51

Why doesn't fastcgi script resume after heavy server load?

After stopping the heavy load on the server (100% load on the cpu within 1-2 hours), the fastcgi script almost stops doing its job. This is expressed in the fact that about 90% of requests to it do not wait for a response from the server.

upstream timed out (110: Connection timed out) while connecting to upstream

The problem is that the script does not "come to life" even after 20 hours of such "work" while not consuming extra memory and cpu resources (compared to stable operation)
in the nginx settings there are such lines
fastcgi_read_timeout 10s;
fastcgi_send_timeout 10s;
fastcgi_connect_timeout 10s;

and in the script itself
int main(void) {
  streambuf * cin_streambuf  = cin.rdbuf();
  streambuf * cout_streambuf = cout.rdbuf();
  streambuf * cerr_streambuf = cerr.rdbuf();

  FCGX_Request request;
  FCGX_Init();
  FCGX_InitRequest(&request, 0, 0);

  srand (time(NULL));

  while (FCGX_Accept_r(&request) == 0) {
    fcgi_streambuf cin_fcgi_streambuf(request.in);
    fcgi_streambuf cout_fcgi_streambuf(request.out);
    fcgi_streambuf cerr_fcgi_streambuf(request.err);

    cin.rdbuf(&cin_fcgi_streambuf);
    cout.rdbuf(&cout_fcgi_streambuf);
    cerr.rdbuf(&cerr_fcgi_streambuf);

    requestNumber++;

    cout << "Pragma: no-cache\r\n";
    cout << "Cache-Control: post-check=0, pre-check=0\r\n";
    cout << "Cache-Control: no-store, no-cache, must-revalidate, max-age=0\r\n";
    cout << "Content-type: text/html\r\n\r\n";
    
    float dl = time(NULL) - atof(FCGX_GetParam("REQUEST_TIME", request.envp));
    if(dl > REQUEST_TIMEOUT) continue; //не обрабатываем запросы ждущие слишком долго

load
n0anm.png
memory
IuPOb.png
Using NGINX
kNSgH.png
PS I'm not strong in c++, especially in situations where the program works in extreme conditions, maybe I'm missing one or another check when creating an object (example: has memory been allocated?)
PPS ubuntu/nginx/php/mysql

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question