eleme / corvus

A fast and lightweight Redis Cluster Proxy for Redis 3.0
MIT License
789 stars 143 forks source link

Allow increasing maxclients #125

Closed offline closed 7 years ago

offline commented 7 years ago

I see that the max clients I was able to reach is 468. Is it something hardcoded or I can change it via settings?

wooparadog commented 7 years ago

Have you checked your fd limit? See

https://www.cyberciti.biz/faq/linux-increase-the-maximum-number-of-open-files/

offline commented 7 years ago
ubuntu@moments-redis-tokyo:~$ cat /proc/sys/fs/file-max
26352901
ubuntu@moments-redis-tokyo:~$ ulimit -Hn
65536
ubuntu@moments-redis-tokyo:~$ ulimit -Sn
1024
ubuntu@moments-redis-tokyo:~$ sysctl fs.file-max
fs.file-max = 26352901
ubuntu@moments-redis-tokyo:~$ ps aux | grep corvus
ubuntu    39511  2.3  0.0 394376 17232 ?        Sl   07:37   8:12 corvus /etc/corvus.conf
doyoubi commented 7 years ago

There's no such limit in corvus. Your soft limit is 1024 which limits the number of connections.

offline commented 7 years ago

Code to reproduce the problem in python

import redis

connections = {}
for i in range(500): 
    connections[i] = redis.StrictRedis(host='localhost', port=6379, db=0)

for key, r in connections.items(): 
    r.get("a")

It will give you exception: ConnectionError: Error while reading from socket: (104, 'Connection reset by peer')

The error is not related to python, because after 468 connections are opened - you can't even connect with redis-cli, it gives same error "Connection reset by peer"

tevino commented 7 years ago

@offline You may have hit the fd limit on your server.

Please post the output of the following command so we can confirm that: cat /proc/<corvus pid>/limits

offline commented 7 years ago
ubuntu@moments-redis-tokyo:~$ cat /proc/39511/limits
Limit                     Soft Limit           Hard Limit           Units
Max cpu time              unlimited            unlimited            seconds
Max file size             unlimited            unlimited            bytes
Max data size             unlimited            unlimited            bytes
Max stack size            8388608              unlimited            bytes
Max core file size        0                    unlimited            bytes
Max resident set          unlimited            unlimited            bytes
Max processes             1031741              1031741              processes
Max open files            1024                 65536                files
Max locked memory         65536                65536                bytes
Max address space         unlimited            unlimited            bytes
Max file locks            unlimited            unlimited            locks
Max pending signals       1031741              1031741              signals
Max msgqueue size         819200               819200               bytes
Max nice priority         0                    0
Max realtime priority     0                    0
Max realtime timeout      unlimited            unlimited            us
tevino commented 7 years ago

And: ls -l /proc/<corvus pid>/fd | wc -l

offline commented 7 years ago

@tevino you are right, here is what I see there when nobody connected:

ubuntu@moments-redis-tokyo:~$ ls -l /proc/39511/fd/
total 0
l-wx------ 1 ubuntu ubuntu 64 May  4 06:50 0 -> /dev/null
l-wx------ 1 ubuntu ubuntu 64 May  4 06:50 1 -> /tmp/nohup.out
lrwx------ 1 ubuntu ubuntu 64 May  4 06:50 10 -> socket:[42985]
lrwx------ 1 ubuntu ubuntu 64 May  4 06:50 11 -> socket:[116060]
lrwx------ 1 ubuntu ubuntu 64 May  4 06:50 119 -> socket:[103327]
lrwx------ 1 ubuntu ubuntu 64 May  4 06:50 12 -> anon_inode:[timerfd]
lrwx------ 1 ubuntu ubuntu 64 May  4 06:50 120 -> socket:[115337]
lrwx------ 1 ubuntu ubuntu 64 May  4 06:50 121 -> socket:[109461]
lrwx------ 1 ubuntu ubuntu 64 May  4 06:50 13 -> anon_inode:[timerfd]
lrwx------ 1 ubuntu ubuntu 64 May  4 06:50 130 -> socket:[134165]
lrwx------ 1 ubuntu ubuntu 64 May  4 06:50 137 -> socket:[110532]
lrwx------ 1 ubuntu ubuntu 64 May  4 06:50 14 -> anon_inode:[timerfd]
lrwx------ 1 ubuntu ubuntu 64 May  4 06:50 144 -> socket:[130267]
lrwx------ 1 ubuntu ubuntu 64 May  4 06:50 15 -> anon_inode:[timerfd]
lrwx------ 1 ubuntu ubuntu 64 May  4 06:50 151 -> socket:[133224]
lrwx------ 1 ubuntu ubuntu 64 May  4 06:50 162 -> socket:[133229]
lrwx------ 1 ubuntu ubuntu 64 May  4 06:50 163 -> socket:[111043]
lrwx------ 1 ubuntu ubuntu 64 May  4 06:50 17 -> socket:[103287]
lrwx------ 1 ubuntu ubuntu 64 May  4 06:50 18 -> socket:[85877]
lrwx------ 1 ubuntu ubuntu 64 May  4 06:50 190 -> socket:[130272]
lrwx------ 1 ubuntu ubuntu 64 May  4 06:50 191 -> socket:[130273]
lrwx------ 1 ubuntu ubuntu 64 May  4 06:50 192 -> socket:[110539]
lrwx------ 1 ubuntu ubuntu 64 May  4 06:50 197 -> socket:[113178]
l-wx------ 1 ubuntu ubuntu 64 May  4 06:50 2 -> /tmp/nohup.out
lrwx------ 1 ubuntu ubuntu 64 May  4 06:50 202 -> socket:[110542]
lrwx------ 1 ubuntu ubuntu 64 May  4 06:50 213 -> socket:[133238]
lrwx------ 1 ubuntu ubuntu 64 May  4 06:50 220 -> socket:[110545]
lrwx------ 1 ubuntu ubuntu 64 May  4 06:50 237 -> socket:[113191]
lrwx------ 1 ubuntu ubuntu 64 May  4 06:50 250 -> socket:[130282]
lrwx------ 1 ubuntu ubuntu 64 May  4 06:50 257 -> socket:[133247]
lrwx------ 1 ubuntu ubuntu 64 May  4 06:50 264 -> socket:[129281]
lrwx------ 1 ubuntu ubuntu 64 May  4 06:50 271 -> socket:[113196]
lrwx------ 1 ubuntu ubuntu 64 May  4 06:50 29 -> socket:[134150]
lrwx------ 1 ubuntu ubuntu 64 May  4 06:50 3 -> anon_inode:[eventpoll]
lrwx------ 1 ubuntu ubuntu 64 May  4 06:50 30 -> socket:[113155]
lrwx------ 1 ubuntu ubuntu 64 May  4 06:50 306 -> socket:[110550]
lrwx------ 1 ubuntu ubuntu 64 May  4 06:50 31 -> socket:[107166]
lrwx------ 1 ubuntu ubuntu 64 May  4 06:50 32 -> socket:[112154]
lrwx------ 1 ubuntu ubuntu 64 May  4 06:50 33 -> socket:[114567]
lrwx------ 1 ubuntu ubuntu 64 May  4 06:50 34 -> socket:[114568]
lrwx------ 1 ubuntu ubuntu 64 May  4 06:50 4 -> anon_inode:[eventpoll]
lrwx------ 1 ubuntu ubuntu 64 May  4 06:50 433 -> socket:[133256]
lrwx------ 1 ubuntu ubuntu 64 May  4 06:50 434 -> socket:[131153]
lrwx------ 1 ubuntu ubuntu 64 May  4 06:50 5 -> anon_inode:[eventpoll]
lrwx------ 1 ubuntu ubuntu 64 May  4 06:50 7 -> anon_inode:[eventpoll]
lrwx------ 1 ubuntu ubuntu 64 May  4 06:50 8 -> socket:[127074]
lrwx------ 1 ubuntu ubuntu 64 May  4 06:50 9 -> socket:[123970]

And here is what I see after 468 clients connected:

ubuntu@moments-redis-tokyo:~$ ls -l /proc/39511/fd/ | wc -l
1024
tevino commented 7 years ago

Glad that you found the cause yourself.

I'm closing this.