Performance

Tested: The Nginx layer directly reads memcahce more than 8 times faster than forwarding php-fpm and then reading memcache

ngx_http_memcached_module

In many scenarios, a single data interface is generally forwarded by nginx to the application layer. For example: php-fpm, django and other related back-end processing. Sometimes it is really troublesome to deploy a complete architecture for one interface.

image.png

The memcached_module module of nginx can directly read the data in the memcache cache server and directly respond to the request. If there is no cached key, it can be directed to the specified back-end processing file through 404

image.png

server {
    location / {
        #www.elephdev.com/cache_123.html will use /cache_123.html as the key to determine whether there is a cache in memcached
        set $memcached_key "$uri";
        memcached_pass 127.0.0.1:11211;
        #Capture the error code information and call back to @fallback for processing
        error_page 404 502 504 = @fallback;
    }

    location @fallback {
        #Can also be forwarded to other services proxy_pass http://backend;
        root /www/elephdev;
        index /nginx_cache_callback.php;
    }
}
点赞(1)

评论列表 共有 0 评论

暂无评论

微信服务号

微信客服

淘宝店铺

support@elephdev.com

发表
评论
Go
顶部