Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NGINX / PHP-FPM: Ajax slow first request, good next ones

  • The CMS is Elxis, which comes from a variant of Joomla (PHP).
    • The server is running nGinx with PHP-FPM
    • All requests get logged and executed, eventually, B U T!!!

When firing a specific request via the URL bar, the request gets executed immediately. However, when fired via ajax (through jQuery), the same request has a very strange behaviour.

Namely: First request (on a media manager), to view picture details, is to be fired with Ajax. It is logged on the browser, but not on the server... Not just yet... After some good 40-50 seconds, the request appears on the server and then it is responded immediately.

All following requests are executed immediately, no problem. Only the first one is rough..

I am in trouble because there is not any error logged anywhere: Everything seems sane, except for the lag of the first request to reach the server...

It is not routing (the site is already up and requests have been served), it is not resolution (the ip is in my /etc/hosts file).

And to add a little cherry on top of the cake, trying to capture packets (tcpdump) on the server produces no output: The request is not here yet... Tried on client too: no output - for at least 40 secs...

It's all on the browser, developer console shows no error, just a pending request.

Does any of this ring a bell to anyone?

The server:
nginx version: nginx/1.6.2
PHP 5.6.7-1 (cli)
PHP 5.6.7-1 (fpm-fcgi)

jQuery version 1.11
The client: tried on Firefox 39 (ubuntu) and Chromium 41

like image 444
Ruby Racer Avatar asked Apr 10 '15 14:04

Ruby Racer


1 Answers

I faced similar kind of problem and i ended up increasing number of php-fpm workers. I used the following settings in www.conf (pool.d) to solve the problem i was facing. I had an analytics server setup which was tracking pageviews and there was a delay of 15-20s in API recording the pageviews. Tuning the following settings solved my problem, maybe it might help you.

pm = dynamic
pm.max_children = 5
pm.start_servers = 2
pm.min_spare_servers = 1
pm.max_spare_servers = 3
like image 193
Mohd Asim Suhail Avatar answered Oct 14 '22 02:10

Mohd Asim Suhail