B
B
bushart2019-07-23 14:56:55
Nginx
bushart, 2019-07-23 14:56:55

How to get rid of getting a request in the queue when using nginx as an image cache?

Hello everyone,
There is an nginx server that serves images according to the following configuration

fastcgi_cache_path /media/ssd18/nginx-documents-cache levels=1:2 keys_zone=documents:100m inactive=30d max_size=250g;
fastcgi_cache_key "$scheme$request_method$host$request_uri";

    location /documents-cache/ {
        try_files $uri /index.php =404;
        fastcgi_pass unix:/run/php/php7.2-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_cache_key   $request_uri;
        fastcgi_cache documents;
        fastcgi_cache_valid 200 30d;
        include fastcgi_params;
    }

Pictures are generated by a php script, but, in theory, they are cached and must be retrieved from the cache for re-access. And it works fine as long as I load 1-2 images per page this way. But there are places on the site where you need to upload 16 pictures at once. And then the system does not work as expected. If I loaded static images without cache, they would be loaded all together, in parallel. But in the case of a cache, the browser downloads the first 5, and keeps the rest in a queue. Having loaded 5 pieces, it is taken for another 5-6, etc.
I checked the number of workers - there are 8 of them, 1024 connections for each - there is definitely no problem in this place. Now I sit and puzzle over why nginx does not want to give all the pictures at once.
Please tell me why this is happening or, at least, in which direction to dig?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
ayazer, 2019-07-23
@bushart

acc. with RFC 2616, the browser limits the number of simultaneous requests to 1 server. And if chrome allows you to simultaneously execute 5-6 requests, then other browsers have an even lower limit. So the problem is not in nginx.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question