Redis too many open files error on high traffic sites

Problem description:
in log file you can find many lines like:

Accepting client connection: accept: Too many open files

To deal with this problem, first check how many connections Redis will handle. This can be find in redis.conf file:

maxclients 4096

Then check current user open file limit:

# ulimit -n

If the limit is not modified, it is usually 1024.
This is more than enought for regular programs, but the Redis server must handle 4096 connections.

Each connection is a file descriptor which is special kind of "open file". Unlike Apache server, Redis is single threaded and runs on single process. This is why it "hits" this limit.

To increase the limit, you need to do:

# ulimit -n 4096

Someone may suggest to do "unlimited" instead of 4096. It will work, but we do not like "unlimited" limits.

Then we need to stop Redis and to start it again.

To make this permanent, you will need to include it in Redis starting script.
If you are using our Lazy starter script, just add "ulimit" command before Redis start.

If you still get same error...

...check and consider increase of global Linux file limit.

To check it do:

# cat /proc/sys/fs/file-max
# cat /proc/sys/fs/file-nr
22040    0       3224798

Here 22040 is currently open files and 3224798 is total open file limit.

If the two numbers are similar, you need to consider increase the total open file limit, using:

# echo 4000000 > /proc/sys/fs/file-max

Do not forget to make change permanent, so limit to be OK after restart.

blog comments powered by Disqus

Articles library

Redis as session handler in PHP

How to use Redis for session handler in PHP in a way similar to msession or PostgreSQL sessions
Date: 2011-07

Tags: php system administration

Lazy starter script on Linux such Redhat CentOS or Fedora

How to quickly made Redis to start after Linux boot.
Date: 2011-07

Tags: system administration

Redis vs Memcached comparison

Here is basic comparison of Redis Memcached and Memcachedb.
Date: 2011-07

Tags: memcached

Why RDBMS and SQL are difficult...

...while sometimes NoSQL solution may be easier and way faster? This arcle deals with incremental counters and how they needs to be implemented properly in RDBMS-es such MySQL
Date: 2011-07
Updated: 2011-09-30

Tags: mysql programming anti-pattern

Seamless migration from one Redis server to another

How to use replication to migrate Redis server without service interruption
Date: 2011-07

Tags: system administration

Redis swap issue while save

Explanation why your server load average may spike and server to swap memory when running redis
Date: 2011-08-21

Tags: system administration

Amazon EC2 and Amazon ElastiCache service

Memcached at Amazon first impressions
Date: 2011-08-23

Tags: memcached cloud system administration

Understanding hash-max-zipmap-entries and 'hash of hashes' optimization

Explanation of config parameters such hash-max-zipmap-entries and how we can make huge memory savings in new Redis 2.2
Date: 2011-08-28

Tags: optimization php programming system administration

NoSQL database design example

This article explains how we made our article section
Date: 2011-09-02

Tags: mysql database design programming

Redis save and backup script

Simple backup script for Redis
Date: 2011-09-28

Tags: optimization system administration

Postgres 9.1 foreign data wrapper interface

Postgres 9.1 gives you ability to access data from different data sources including Redis
Date: 2011-10-20

Tags: memcached optimization mysql programming pgsql

Redis high traffic connection issue

Explanation on 'Cannot assign requested address' connection error
Date: 2011-11-12

Tags: optimization scaling system administration

Redis too many open files error on high traffic sites

Explanation on 'Accepting client connection: accept: Too many open files'
Date: 2011-12-21

Tags: memcached security system administration

PHP Redis bug with PHP 5.4

Description of bug PHP Redis bug
Date: 2012-07-02

Tags: php system administration

Case Study: Using Redis intersect on very large sets

Intersection of 2 x 120M MySQL records
Date: 2012-08-29

Tags: optimization cloud php mysql programming

Getting started with Python and Redis on CentOS 6.X

How to install and test Redis client for Python on CentOS
Date: 2013-03-21

Tags: python system administration

GeoIP in Redis

Put Maxmind's GeoIP in Redis for best berformance for cient apps written in PHP or Python
Date: 2013-03-24

Tags: optimization php scaling mysql programming python

Redis database file examination

Examination of Redis rdb file in order to find huge memory consumption
Date: 2013-08-23

Tags: optimization system administration

© Jul.2011 - 2019,
This website uses cookies to improve user experience. By using our website you consent to all cookies in accordance with our Cookie Policy.