The Time to Send memcached in Nginx

nginx memcached send timeout
31 March 2025

Understanding the memcached Module in Nginx

The ngx_http_memcached_module in Nginx allows us to use the Memcached server as one of the caching sources for our data. This method is widely appreciated among web developers due to its capability in increasing response speed and reducing the load on primary servers. However, to effectively use this module, we need to familiarize ourselves with its various configurations.

One of the key configurations in this module is memcached_send_timeout. This setting determines the duration for which Nginx waits for a response from the Memcached server during data requests. If the wait time exceeds the specified duration in memcached_send_timeout, Nginx will terminate the connection. This prevents unnecessary delays and avoids resource starvation.

The memcached_send_timeout value may be sufficient for most users; however, in specific situations, such as when you have high network traffic or multiple requests being sent to Memcached, you may need to increase this value. Generally, the default time is 60 seconds, which is suitable for most sites.

Now, let’s see how we can set this configuration in the Nginx configuration file. To do this, you need to edit the Nginx configuration file (commonly located at /etc/nginx/nginx.conf) and add the settings related to the Memcached module.

Code Example

location /memcached {
memcached_pass 127.0.0.1:11211;
default_type text/html;
memcached_send_timeout 30s;
}

Code Explanation

Here, we will review the above code step by step:

  • location /memcached: This line tells Nginx that whenever a request is sent to the path /memcached, it should apply the configurations defined in this block.
  • memcached_pass 127.0.0.1:11211: This line specifies which Memcached server to send the requests to. Here, it is using localhost at port 11211.
  • default_type text/html: It instructs Nginx that the default content type for responses to the requests will be HTML.
  • memcached_send_timeout 30s: This line indicates that if Nginx cannot connect to the Memcached server within 30 seconds, it should terminate the connection.

FAQ

?

What is the purpose of the memcached send time?

?

How can I increase the memcached send time?

?

Is the default memcached_send_timeout time sufficient?

?

What happens if the send time exceeds the limit?