flashmob / go-guerrilla

Mini SMTP server written in golang
MIT License
2.78k stars 366 forks source link

dial tcp 127.0.0.1:3306: socket: too many open files #186

Closed lord-alfred closed 5 years ago

lord-alfred commented 5 years ago

Tonight I got a lot of errors in log when almost 30 thousand letters arrived in a short time:

time="2019-09-03T08:00:06+03:00" level=error msg="doQuery error" error="dial tcp 127.0.0.1:3306: socket: too many open files"
time="2019-09-03T08:00:06+03:00" level=error msg="doQuery error" error="dial tcp 127.0.0.1:3306: socket: too many open files"
time="2019-09-03T08:00:06+03:00" level=error msg="doQuery error" error="dial tcp 127.0.0.1:3306: socket: too many open files"
time="2019-09-03T08:00:06+03:00" level=error msg="There was a problem the insert" error="dial tcp 127.0.0.1:3306: socket: too many open files"
time="2019-09-03T08:00:06+03:00" level=error msg="There was a problem the insert" error="dial tcp 127.0.0.1:3306: socket: too many open files"
time="2019-09-03T08:00:06+03:00" level=error msg="storage error"
time="2019-09-03T08:00:06+03:00" level=error msg="storage error"
time="2019-09-03T08:00:06+03:00" level=error msg="storage error"

But my limits is:

$ ulimit -a
core file size          (blocks, -c) 0
data seg size           (kbytes, -d) unlimited
scheduling priority             (-e) 0
file size               (blocks, -f) unlimited
pending signals                 (-i) 31784
max locked memory       (kbytes, -l) 64
max memory size         (kbytes, -m) unlimited
open files                      (-n) 65535
pipe size            (512 bytes, -p) 8
POSIX message queues     (bytes, -q) 819200
real-time priority              (-r) 0
stack size              (kbytes, -s) 8192
cpu time               (seconds, -t) unlimited
max user processes              (-u) 65535
virtual memory          (kbytes, -v) unlimited
file locks                      (-x) unlimited

And when I installed I did the following:

# limitations: https://medium.com/@muhammadtriwibowo/set-permanently-ulimit-n-open-files-in-ubuntu-4d61064429a
ulimit -n 65535
/bin/su -c "echo 'fs.file-max = 65535' >> /etc/sysctl.conf"
sysctl -p

/bin/su -c "echo '* soft     nproc          65535' >> /etc/security/limits.conf"
/bin/su -c "echo '* hard     nproc          65535' >> /etc/security/limits.conf"
/bin/su -c "echo '* soft     nofile         65535' >> /etc/security/limits.conf"
/bin/su -c "echo '* hard     nofile         65535' >> /etc/security/limits.conf"
/bin/su -c "echo 'root soft     nproc          65535' >> /etc/security/limits.conf"
/bin/su -c "echo 'root hard     nproc          65535' >> /etc/security/limits.conf"
/bin/su -c "echo 'root soft     nofile         65535' >> /etc/security/limits.conf"
/bin/su -c "echo 'root hard     nofile         65535' >> /etc/security/limits.conf"

/bin/su -c "echo 'session required pam_limits.so' >> /etc/pam.d/common-session"

My config is:

{
...
    "backend_config": {
...
        "save_workers_size": 250,
        "save_process": "HeadersParser|Hasher|Header|BenderSql",
...
        "gw_save_timeout": "30s",
        "gw_val_rcpt_timeout": "3s",
        "sql_driver": "mysql",
        "sql_dsn": "BM_DB_USERNAME:BM_DB_PASSWORD@tcp(BM_DB_HOST:BM_DB_PORT)/BM_DB_DATABASE?readTimeout=10s&writeTimeout=10s&charset=utf8mb4&collation=utf8mb4_unicode_ci",
        "mail_table": "messages",
        "sql_max_open_conns": 250,
        "sql_max_idle_conns": 150,
        "sql_max_conn_lifetime": "200s"
    },
    "servers": [
        {
...
            "max_size": 3145728,
            "timeout":180,
            "listen_interface":"0.0.0.0:25",
            "max_clients": 1000,
...
        },
        {
...
            "timeout":15,
            "listen_interface":"127.0.0.1:2525",
            "max_clients": 10,
...
        }
    ]
}

(second server need for monit task)

Need a larger limit, or somewhere there may be a mistake?

PS: Ubuntu 16.04 x64, 8CPU cores / 8GB RAM

flashmob commented 5 years ago

What is the output of

sudo lsof | wc -l

probably there is a a tutorial for more lsof command options that will let you drill down to see who

Also, decrease your save_workers_size workers to about 2 or 4.

On Tue., 3 Sep. 2019, 16:25 Lord Alfred, notifications@github.com wrote:

Tonight I got a lot of errors in log when almost 30 thousand letters arrived in a short time:

time="2019-09-03T08:00:06+03:00" level=error msg="doQuery error" error="dial tcp 127.0.0.1:3306: socket: too many open files" time="2019-09-03T08:00:06+03:00" level=error msg="doQuery error" error="dial tcp 127.0.0.1:3306: socket: too many open files" time="2019-09-03T08:00:06+03:00" level=error msg="doQuery error" error="dial tcp 127.0.0.1:3306: socket: too many open files" time="2019-09-03T08:00:06+03:00" level=error msg="There was a problem the insert" error="dial tcp 127.0.0.1:3306: socket: too many open files" time="2019-09-03T08:00:06+03:00" level=error msg="There was a problem the insert" error="dial tcp 127.0.0.1:3306: socket: too many open files" time="2019-09-03T08:00:06+03:00" level=error msg="storage error" time="2019-09-03T08:00:06+03:00" level=error msg="storage error" time="2019-09-03T08:00:06+03:00" level=error msg="storage error"

But my limits is:

$ ulimit -a core file size (blocks, -c) 0 data seg size (kbytes, -d) unlimited scheduling priority (-e) 0 file size (blocks, -f) unlimited pending signals (-i) 31784 max locked memory (kbytes, -l) 64 max memory size (kbytes, -m) unlimited open files (-n) 65535 pipe size (512 bytes, -p) 8 POSIX message queues (bytes, -q) 819200 real-time priority (-r) 0 stack size (kbytes, -s) 8192 cpu time (seconds, -t) unlimited max user processes (-u) 65535 virtual memory (kbytes, -v) unlimited file locks (-x) unlimited

And when I installed I did the following:

limitations: https://medium.com/@muhammadtriwibowo/set-permanently-ulimit-n-open-files-in-ubuntu-4d61064429a

ulimit -n 65535 /bin/su -c "echo 'fs.file-max = 65535' >> /etc/sysctl.conf" sysctl -p

/bin/su -c "echo ' soft nproc 65535' >> /etc/security/limits.conf" /bin/su -c "echo ' hard nproc 65535' >> /etc/security/limits.conf" /bin/su -c "echo ' soft nofile 65535' >> /etc/security/limits.conf" /bin/su -c "echo ' hard nofile 65535' >> /etc/security/limits.conf" /bin/su -c "echo 'root soft nproc 65535' >> /etc/security/limits.conf" /bin/su -c "echo 'root hard nproc 65535' >> /etc/security/limits.conf" /bin/su -c "echo 'root soft nofile 65535' >> /etc/security/limits.conf" /bin/su -c "echo 'root hard nofile 65535' >> /etc/security/limits.conf"

/bin/su -c "echo 'session required pam_limits.so' >> /etc/pam.d/common-session"

My config is:

{... "backend_config": {... "save_workers_size": 250, "save_process": "HeadersParser|Hasher|Header|BenderSql",... "gw_save_timeout": "30s", "gw_val_rcpt_timeout": "3s", "sql_driver": "mysql", "sql_dsn": "BM_DB_USERNAME:BM_DB_PASSWORD@tcp(BM_DB_HOST:BM_DB_PORT)/BM_DB_DATABASE?readTimeout=10s&writeTimeout=10s&charset=utf8mb4&collation=utf8mb4_unicode_ci", "mail_table": "messages", "sql_max_open_conns": 250, "sql_max_idle_conns": 150, "sql_max_conn_lifetime": "200s" }, "servers": [ {... "max_size": 3145728, "timeout":180, "listen_interface":"0.0.0.0:25", "max_clients": 1000,... }, {... "timeout":15, "listen_interface":"127.0.0.1:2525", "max_clients": 10,... } ] }

Need a larger limit, or somewhere there may be a mistake?

PS: Ubuntu 16.04 x64, 8CPU cores / 8GB RAM

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/flashmob/go-guerrilla/issues/186?email_source=notifications&email_token=AAE6MP3N5P5AO42HTWR23OLQHYGPZA5CNFSM4ITC35U2YY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4HI46NBA, or mute the thread https://github.com/notifications/unsubscribe-auth/AAE6MP7ATVZP2SOGKVKWP4LQHYGPZANCNFSM4ITC35UQ .

lord-alfred commented 5 years ago
$ sudo lsof | wc -l
70161

sudo lsof | grep guerrilla
COMMAND     PID   TID             USER   FD      TYPE             DEVICE  SIZE/OFF       NODE NAME
sudo      27554                   root    1w      REG              253,1     20721     268593 /var/log/guerrilla/daemon.log
sudo      27554                   root    2w      REG              253,1     20721     268593 /var/log/guerrilla/daemon.log
sh        27556                  guser    1w      REG              253,1     20721     268593 /var/log/guerrilla/daemon.log
sh        27556                  guser    2w      REG              253,1     20721     268593 /var/log/guerrilla/daemon.log
guerrilla 27561                  guser  cwd       DIR              253,1      4096     267024 /home/guser
guerrilla 27561                  guser  rtd       DIR              253,1      4096          2 /
guerrilla 27561                  guser  txt       REG              253,1  15208236         17 /usr/local/bin/guerrillad
guerrilla 27561                  guser  mem       REG              253,1   1868984       1295 /lib/x86_64-linux-gnu/libc-2.23.so
guerrilla 27561                  guser  mem       REG              253,1    138696       1382 /lib/x86_64-linux-gnu/libpthread-2.23.so
guerrilla 27561                  guser  mem       REG              253,1    162632       1271 /lib/x86_64-linux-gnu/ld-2.23.so
guerrilla 27561                  guser    0r      CHR                1,3       0t0          6 /dev/null
guerrilla 27561                  guser    1w      REG              253,1     20721     268593 /var/log/guerrilla/daemon.log
guerrilla 27561                  guser    2w      REG              253,1     20721     268593 /var/log/guerrilla/daemon.log
guerrilla 27561                  guser    3u     sock                0,8       0t0      91330 protocol: TCP
guerrilla 27561                  guser    4u  a_inode               0,11         0       7050 [eventpoll]
guerrilla 27561                  guser    5u     sock                0,8       0t0      85889 protocol: TCP
guerrilla 27561                  guser    6u     sock                0,8       0t0      89697 protocol: TCP
guerrilla 27561                  guser    7u     sock                0,8       0t0      93198 protocol: TCP
guerrilla 27561                  guser    8u     sock                0,8       0t0      93199 protocol: TCP
guerrilla 27561                  guser    9u     sock                0,8       0t0      90310 protocol: TCP
guerrilla 27561                  guser   10u     sock                0,8       0t0      93200 protocol: TCP
...
guerrilla 27561                  guser  251u     sock                0,8       0t0      89749 protocol: TCP
guerrilla 27561                  guser  252u     sock                0,8       0t0      89750 protocol: TCP
guerrilla 27561                  guser  253u     sock                0,8       0t0      93266 protocol: TCP
guerrilla 27561                  guser  254w      REG              253,1         0     268596 /var/log/guerrilla/server.log
guerrilla 27561                  guser  255u     IPv4              89751       0t0        TCP localhost:2525 (LISTEN)
guerrilla 27561                  guser  256w      REG              253,1    498328     268597 /var/log/guerrilla/main.log
guerrilla 27561                  guser  257u     IPv6              93270       0t0        TCP *:smtp (LISTEN)
guerrilla 27561                  guser  258u     IPv4           12271306       0t0        TCP localhost:44036->localhost:mysql (ESTABLISHED)
guerrilla 27561                  guser  259u     IPv4           12271356       0t0        TCP localhost:44064->localhost:mysql (ESTABLISHED)
guerrilla 27561                  guser  260u     IPv4           12394687       0t0        TCP localhost:44320->localhost:mysql (ESTABLISHED)
guerrilla 27561                  guser  261u     IPv4           12394692       0t0        TCP localhost:44322->localhost:mysql (ESTABLISHED)
guerrilla 27561                  guser  262u     IPv4           12394667       0t0        TCP localhost:44306->localhost:mysql (ESTABLISHED)
...
guerrilla 27561                  guser  470u     IPv4           12394997       0t0        TCP localhost:44518->localhost:mysql (ESTABLISHED)
guerrilla 27561                  guser  471u     IPv4           12394991       0t0        TCP localhost:44512->localhost:mysql (ESTABLISHED)
guerrilla 27561   388            guser  cwd       DIR              253,1      4096     267024 /home/guser
guerrilla 27561   388            guser  rtd       DIR              253,1      4096          2 /
guerrilla 27561   388            guser  txt       REG              253,1  15208236         17 /usr/local/bin/guerrillad
guerrilla 27561   388            guser  mem       REG              253,1   1868984       1295 /lib/x86_64-linux-gnu/libc-2.23.so
guerrilla 27561   388            guser  mem       REG              253,1    138696       1382 /lib/x86_64-linux-gnu/libpthread-2.23.so
guerrilla 27561   388            guser  mem       REG              253,1    162632       1271 /lib/x86_64-linux-gnu/ld-2.23.so
guerrilla 27561   388            guser    0r      CHR                1,3       0t0          6 /dev/null
guerrilla 27561   388            guser    1w      REG              253,1     20721     268593 /var/log/guerrilla/daemon.log
guerrilla 27561   388            guser    2w      REG              253,1     20721     268593 /var/log/guerrilla/daemon.log
guerrilla 27561   388            guser    3u     sock                0,8       0t0      91330 protocol: TCP
guerrilla 27561   388            guser    4u  a_inode               0,11         0       7050 [eventpoll]
guerrilla 27561   388            guser    5u     sock                0,8       0t0      85889 protocol: TCP
...
guerrilla 27561   388            guser  252u     sock                0,8       0t0      89750 protocol: TCP
guerrilla 27561   388            guser  253u     sock                0,8       0t0      93266 protocol: TCP
guerrilla 27561   388            guser  254w      REG              253,1         0     268596 /var/log/guerrilla/server.log
guerrilla 27561   388            guser  255u     IPv4              89751       0t0        TCP localhost:2525 (LISTEN)
guerrilla 27561   388            guser  256w      REG              253,1    498328     268597 /var/log/guerrilla/main.log
guerrilla 27561   388            guser  257u     IPv6              93270       0t0        TCP *:smtp (LISTEN)
guerrilla 27561   388            guser  258u     IPv4           12271306       0t0        TCP localhost:44036->localhost:mysql (ESTABLISHED)
guerrilla 27561   388            guser  259u     IPv4           12271356       0t0        TCP localhost:44064->localhost:mysql (ESTABLISHED)
...
guerrilla 27561   388            guser  470u     IPv4           12394997       0t0        TCP localhost:44518->localhost:mysql (ESTABLISHED)
guerrilla 27561   388            guser  471u     IPv4           12394991       0t0        TCP localhost:44512->localhost:mysql (ESTABLISHED)
guerrilla 27561  2749            guser  cwd       DIR              253,1      4096     267024 /home/guser
guerrilla 27561  2749            guser  rtd       DIR              253,1      4096          2 /
guerrilla 27561  2749            guser  txt       REG              253,1  15208236         17 /usr/local/bin/guerrillad
guerrilla 27561  2749            guser  mem       REG              253,1   1868984       1295 /lib/x86_64-linux-gnu/libc-2.23.so
guerrilla 27561  2749            guser  mem       REG              253,1    138696       1382 /lib/x86_64-linux-gnu/libpthread-2.23.so
guerrilla 27561  2749            guser  mem       REG              253,1    162632       1271 /lib/x86_64-linux-gnu/ld-2.23.so
guerrilla 27561  2749            guser    0r      CHR                1,3       0t0          6 /dev/null
guerrilla 27561  2749            guser    1w      REG              253,1     20721     268593 /var/log/guerrilla/daemon.log
guerrilla 27561  2749            guser    2w      REG              253,1     20721     268593 /var/log/guerrilla/daemon.log
guerrilla 27561  2749            guser    3u     sock                0,8       0t0      91330 protocol: TCP
guerrilla 27561  2749            guser    4u  a_inode               0,11         0       7050 [eventpoll]
guerrilla 27561  2749            guser    5u     sock                0,8       0t0      85889 protocol: TCP
guerrilla 27561  2749            guser    6u     sock                0,8       0t0      89697 protocol: TCP
guerrilla 27561  2749            guser    7u     sock                0,8       0t0      93198 protocol: TCP
guerrilla 27561  2749            guser    8u     sock                0,8       0t0      93199 protocol: TCP
...
guerrilla 27561  2749            guser  251u     sock                0,8       0t0      89749 protocol: TCP
guerrilla 27561  2749            guser  252u     sock                0,8       0t0      89750 protocol: TCP
guerrilla 27561  2749            guser  253u     sock                0,8       0t0      93266 protocol: TCP
guerrilla 27561  2749            guser  254w      REG              253,1         0     268596 /var/log/guerrilla/server.log
guerrilla 27561  2749            guser  255u     IPv4              89751       0t0        TCP localhost:2525 (LISTEN)
guerrilla 27561  2749            guser  256w      REG              253,1    498328     268597 /var/log/guerrilla/main.log
guerrilla 27561  2749            guser  257u     IPv6              93270       0t0        TCP *:smtp (LISTEN)
guerrilla 27561  2749            guser  258u     IPv4           12271306       0t0        TCP localhost:44036->localhost:mysql (ESTABLISHED)
guerrilla 27561  2749            guser  259u     IPv4           12271356       0t0        TCP localhost:44064->localhost:mysql (ESTABLISHED)
guerrilla 27561  2749            guser  260u     IPv4           12394687       0t0        TCP localhost:44320->localhost:mysql (ESTABLISHED)
...
guerrilla 27561  2749            guser  470u     IPv4           12394997       0t0        TCP localhost:44518->localhost:mysql (ESTABLISHED)
guerrilla 27561  2749            guser  471u     IPv4           12394991       0t0        TCP localhost:44512->localhost:mysql (ESTABLISHED)
guerrilla 27561  2750            guser  cwd       DIR              253,1      4096     267024 /home/guser
guerrilla 27561  2750            guser  rtd       DIR              253,1      4096          2 /
guerrilla 27561  2750            guser  txt       REG              253,1  15208236         17 /usr/local/bin/guerrillad
guerrilla 27561  2750            guser  mem       REG              253,1   1868984       1295 /lib/x86_64-linux-gnu/libc-2.23.so
guerrilla 27561  2750            guser  mem       REG              253,1    138696       1382 /lib/x86_64-linux-gnu/libpthread-2.23.so
guerrilla 27561  2750            guser  mem       REG              253,1    162632       1271 /lib/x86_64-linux-gnu/ld-2.23.so
guerrilla 27561  2750            guser    0r      CHR                1,3       0t0          6 /dev/null
guerrilla 27561  2750            guser    1w      REG              253,1     20721     268593 /var/log/guerrilla/daemon.log
guerrilla 27561  2750            guser    2w      REG              253,1     20721     268593 /var/log/guerrilla/daemon.log
guerrilla 27561  2750            guser    3u     sock                0,8       0t0      91330 protocol: TCP
guerrilla 27561  2750            guser    4u  a_inode               0,11         0       7050 [eventpoll]
guerrilla 27561  2750            guser    5u     sock                0,8       0t0      85889 protocol: TCP
guerrilla 27561  2750            guser    6u     sock                0,8       0t0      89697 protocol: TCP
guerrilla 27561  2750            guser    7u     sock                0,8       0t0      93198 protocol: TCP
...
guerrilla 27561  2750            guser  251u     sock                0,8       0t0      89749 protocol: TCP
guerrilla 27561  2750            guser  252u     sock                0,8       0t0      89750 protocol: TCP
guerrilla 27561  2750            guser  253u     sock                0,8       0t0      93266 protocol: TCP
guerrilla 27561  2750            guser  254w      REG              253,1         0     268596 /var/log/guerrilla/server.log
guerrilla 27561  2750            guser  255u     IPv4              89751       0t0        TCP localhost:2525 (LISTEN)
guerrilla 27561  2750            guser  256w      REG              253,1    498328     268597 /var/log/guerrilla/main.log
guerrilla 27561  2750            guser  257u     IPv6              93270       0t0        TCP *:smtp (LISTEN)
guerrilla 27561  2750            guser  258u     IPv4           12271306       0t0        TCP localhost:44036->localhost:mysql (ESTABLISHED)
guerrilla 27561  2750            guser  259u     IPv4           12271356       0t0        TCP localhost:44064->localhost:mysql (ESTABLISHED)
...
guerrilla 27561  2750            guser  469u     IPv4           12394986       0t0        TCP localhost:44510->localhost:mysql (ESTABLISHED)
guerrilla 27561  2750            guser  470u     IPv4           12394997       0t0        TCP localhost:44518->localhost:mysql (ESTABLISHED)
guerrilla 27561  2750            guser  471u     IPv4           12394991       0t0        TCP localhost:44512->localhost:mysql (ESTABLISHED)
guerrilla 27561  3387            guser  cwd       DIR              253,1      4096     267024 /home/guser
guerrilla 27561  3387            guser  rtd       DIR              253,1      4096          2 /
guerrilla 27561  3387            guser  txt       REG              253,1  15208236         17 /usr/local/bin/guerrillad
guerrilla 27561  3387            guser  mem       REG              253,1   1868984       1295 /lib/x86_64-linux-gnu/libc-2.23.so
guerrilla 27561  3387            guser  mem       REG              253,1    138696       1382 /lib/x86_64-linux-gnu/libpthread-2.23.so
guerrilla 27561  3387            guser  mem       REG              253,1    162632       1271 /lib/x86_64-linux-gnu/ld-2.23.so
guerrilla 27561  3387            guser    0r      CHR                1,3       0t0          6 /dev/null
guerrilla 27561  3387            guser    1w      REG              253,1     20721     268593 /var/log/guerrilla/daemon.log
guerrilla 27561  3387            guser    2w      REG              253,1     20721     268593 /var/log/guerrilla/daemon.log
guerrilla 27561  3387            guser    3u     sock                0,8       0t0      91330 protocol: TCP
guerrilla 27561  3387            guser    4u  a_inode               0,11         0       7050 [eventpoll]
guerrilla 27561  3387            guser    5u     sock                0,8       0t0      85889 protocol: TCP
guerrilla 27561  3387            guser    6u     sock                0,8       0t0      89697 protocol: TCP
guerrilla 27561  3387            guser    7u     sock                0,8       0t0      93198 protocol: TCP
...
guerrilla 27561  3387            guser  252u     sock                0,8       0t0      89750 protocol: TCP
guerrilla 27561  3387            guser  253u     sock                0,8       0t0      93266 protocol: TCP
guerrilla 27561  3387            guser  254w      REG              253,1         0     268596 /var/log/guerrilla/server.log
guerrilla 27561  3387            guser  255u     IPv4              89751       0t0        TCP localhost:2525 (LISTEN)
guerrilla 27561  3387            guser  256w      REG              253,1    498328     268597 /var/log/guerrilla/main.log
guerrilla 27561  3387            guser  257u     IPv6              93270       0t0        TCP *:smtp (LISTEN)
guerrilla 27561  3387            guser  258u     IPv4           12271306       0t0        TCP localhost:44036->localhost:mysql (ESTABLISHED)
guerrilla 27561  3387            guser  259u     IPv4           12271356       0t0        TCP localhost:44064->localhost:mysql (ESTABLISHED)
guerrilla 27561  3387            guser  260u     IPv4           12394687       0t0        TCP localhost:44320->localhost:mysql (ESTABLISHED)
...
guerrilla 27561  3387            guser  470u     IPv4           12394997       0t0        TCP localhost:44518->localhost:mysql (ESTABLISHED)
guerrilla 27561  3387            guser  471u     IPv4           12394991       0t0        TCP localhost:44512->localhost:mysql (ESTABLISHED)
guerrilla 27561  3692            guser  cwd       DIR              253,1      4096     267024 /home/guser
guerrilla 27561  3692            guser  rtd       DIR              253,1      4096          2 /
guerrilla 27561  3692            guser  txt       REG              253,1  15208236         17 /usr/local/bin/guerrillad
guerrilla 27561  3692            guser  mem       REG              253,1   1868984       1295 /lib/x86_64-linux-gnu/libc-2.23.so
guerrilla 27561  3692            guser  mem       REG              253,1    138696       1382 /lib/x86_64-linux-gnu/libpthread-2.23.so
guerrilla 27561  3692            guser  mem       REG              253,1    162632       1271 /lib/x86_64-linux-gnu/ld-2.23.so
guerrilla 27561  3692            guser    0r      CHR                1,3       0t0          6 /dev/null
guerrilla 27561  3692            guser    1w      REG              253,1     20721     268593 /var/log/guerrilla/daemon.log
guerrilla 27561  3692            guser    2w      REG              253,1     20721     268593 /var/log/guerrilla/daemon.log
guerrilla 27561  3692            guser    3u     sock                0,8       0t0      91330 protocol: TCP
guerrilla 27561  3692            guser    4u  a_inode               0,11         0       7050 [eventpoll]
guerrilla 27561  3692            guser    5u     sock                0,8       0t0      85889 protocol: TCP
...

Ok, I will test working with less count of save_workers_size (I think, 16 - this is a good starting number).

PS: maybe this is due to https://github.com/flashmob/go-guerrilla/issues/184 ?

flashmob commented 5 years ago

Nope, nothing to do with that issue... Under the hood, goroutines are actually running in the Go runtime level, so the OS won't see them.

Normally, Go creates a new process for each CPU core, (something to do with "CPU affinity" BTW) and then one for the runtime including the garbage collector and goroutine scheduler (or something like that, sorry, not sure of the exact details right now).

So even if you have thousands of goroutines, you will only see just a bunch of processes.

Anyhow, try decreasing that worker count. For a small VPS, would recommend 2 at most, especially if you're not using SSD drives.

Other things can be tuned too, such as the to keep-alive setting in the Linux kernel and so on... Perhaps there are some good ideas here “Tuning your Linux kernel and HAProxy instance for high loads” by Pawel Chmielinski https://link.medium.com/45V3aFKiGZ

On Tue., 3 Sep. 2019, 19:25 Lord Alfred, notifications@github.com wrote:

$ sudo lsof | wc -l 70161

sudo lsof | grep guerrilla COMMAND PID TID USER FD TYPE DEVICE SIZE/OFF NODE NAME sudo 27554 root 1w REG 253,1 20721 268593 /var/log/guerrilla/daemon.log sudo 27554 root 2w REG 253,1 20721 268593 /var/log/guerrilla/daemon.log sh 27556 guser 1w REG 253,1 20721 268593 /var/log/guerrilla/daemon.log sh 27556 guser 2w REG 253,1 20721 268593 /var/log/guerrilla/daemon.log guerrilla 27561 guser cwd DIR 253,1 4096 267024 /home/guser guerrilla 27561 guser rtd DIR 253,1 4096 2 / guerrilla 27561 guser txt REG 253,1 15208236 17 /usr/local/bin/guerrillad guerrilla 27561 guser mem REG 253,1 1868984 1295 /lib/x86_64-linux-gnu/libc-2.23.so guerrilla 27561 guser mem REG 253,1 138696 1382 /lib/x86_64-linux-gnu/libpthread-2.23.so guerrilla 27561 guser mem REG 253,1 162632 1271 /lib/x86_64-linux-gnu/ld-2.23.so guerrilla 27561 guser 0r CHR 1,3 0t0 6 /dev/null guerrilla 27561 guser 1w REG 253,1 20721 268593 /var/log/guerrilla/daemon.log guerrilla 27561 guser 2w REG 253,1 20721 268593 /var/log/guerrilla/daemon.log guerrilla 27561 guser 3u sock 0,8 0t0 91330 protocol: TCP guerrilla 27561 guser 4u a_inode 0,11 0 7050 [eventpoll] guerrilla 27561 guser 5u sock 0,8 0t0 85889 protocol: TCP guerrilla 27561 guser 6u sock 0,8 0t0 89697 protocol: TCP guerrilla 27561 guser 7u sock 0,8 0t0 93198 protocol: TCP guerrilla 27561 guser 8u sock 0,8 0t0 93199 protocol: TCP guerrilla 27561 guser 9u sock 0,8 0t0 90310 protocol: TCP guerrilla 27561 guser 10u sock 0,8 0t0 93200 protocol: TCP ... guerrilla 27561 guser 251u sock 0,8 0t0 89749 protocol: TCP guerrilla 27561 guser 252u sock 0,8 0t0 89750 protocol: TCP guerrilla 27561 guser 253u sock 0,8 0t0 93266 protocol: TCP guerrilla 27561 guser 254w REG 253,1 0 268596 /var/log/guerrilla/server.log guerrilla 27561 guser 255u IPv4 89751 0t0 TCP localhost:2525 (LISTEN) guerrilla 27561 guser 256w REG 253,1 498328 268597 /var/log/guerrilla/main.log guerrilla 27561 guser 257u IPv6 93270 0t0 TCP :smtp (LISTEN) guerrilla 27561 guser 258u IPv4 12271306 0t0 TCP localhost:44036->localhost:mysql (ESTABLISHED) guerrilla 27561 guser 259u IPv4 12271356 0t0 TCP localhost:44064->localhost:mysql (ESTABLISHED) guerrilla 27561 guser 260u IPv4 12394687 0t0 TCP localhost:44320->localhost:mysql (ESTABLISHED) guerrilla 27561 guser 261u IPv4 12394692 0t0 TCP localhost:44322->localhost:mysql (ESTABLISHED) guerrilla 27561 guser 262u IPv4 12394667 0t0 TCP localhost:44306->localhost:mysql (ESTABLISHED) ... guerrilla 27561 guser 470u IPv4 12394997 0t0 TCP localhost:44518->localhost:mysql (ESTABLISHED) guerrilla 27561 guser 471u IPv4 12394991 0t0 TCP localhost:44512->localhost:mysql (ESTABLISHED) guerrilla 27561 388 guser cwd DIR 253,1 4096 267024 /home/guser guerrilla 27561 388 guser rtd DIR 253,1 4096 2 / guerrilla 27561 388 guser txt REG 253,1 15208236 17 /usr/local/bin/guerrillad guerrilla 27561 388 guser mem REG 253,1 1868984 1295 /lib/x86_64-linux-gnu/libc-2.23.so guerrilla 27561 388 guser mem REG 253,1 138696 1382 /lib/x86_64-linux-gnu/libpthread-2.23.so guerrilla 27561 388 guser mem REG 253,1 162632 1271 /lib/x86_64-linux-gnu/ld-2.23.so guerrilla 27561 388 guser 0r CHR 1,3 0t0 6 /dev/null guerrilla 27561 388 guser 1w REG 253,1 20721 268593 /var/log/guerrilla/daemon.log guerrilla 27561 388 guser 2w REG 253,1 20721 268593 /var/log/guerrilla/daemon.log guerrilla 27561 388 guser 3u sock 0,8 0t0 91330 protocol: TCP guerrilla 27561 388 guser 4u a_inode 0,11 0 7050 [eventpoll] guerrilla 27561 388 guser 5u sock 0,8 0t0 85889 protocol: TCP ... guerrilla 27561 388 guser 252u sock 0,8 0t0 89750 protocol: TCP guerrilla 27561 388 guser 253u sock 0,8 0t0 93266 protocol: TCP guerrilla 27561 388 guser 254w REG 253,1 0 268596 /var/log/guerrilla/server.log guerrilla 27561 388 guser 255u IPv4 89751 0t0 TCP localhost:2525 (LISTEN) guerrilla 27561 388 guser 256w REG 253,1 498328 268597 /var/log/guerrilla/main.log guerrilla 27561 388 guser 257u IPv6 93270 0t0 TCP :smtp (LISTEN) guerrilla 27561 388 guser 258u IPv4 12271306 0t0 TCP localhost:44036->localhost:mysql (ESTABLISHED) guerrilla 27561 388 guser 259u IPv4 12271356 0t0 TCP localhost:44064->localhost:mysql (ESTABLISHED) ... guerrilla 27561 388 guser 470u IPv4 12394997 0t0 TCP localhost:44518->localhost:mysql (ESTABLISHED) guerrilla 27561 388 guser 471u IPv4 12394991 0t0 TCP localhost:44512->localhost:mysql (ESTABLISHED) guerrilla 27561 2749 guser cwd DIR 253,1 4096 267024 /home/guser guerrilla 27561 2749 guser rtd DIR 253,1 4096 2 / guerrilla 27561 2749 guser txt REG 253,1 15208236 17 /usr/local/bin/guerrillad guerrilla 27561 2749 guser mem REG 253,1 1868984 1295 /lib/x86_64-linux-gnu/libc-2.23.so guerrilla 27561 2749 guser mem REG 253,1 138696 1382 /lib/x86_64-linux-gnu/libpthread-2.23.so guerrilla 27561 2749 guser mem REG 253,1 162632 1271 /lib/x86_64-linux-gnu/ld-2.23.so guerrilla 27561 2749 guser 0r CHR 1,3 0t0 6 /dev/null guerrilla 27561 2749 guser 1w REG 253,1 20721 268593 /var/log/guerrilla/daemon.log guerrilla 27561 2749 guser 2w REG 253,1 20721 268593 /var/log/guerrilla/daemon.log guerrilla 27561 2749 guser 3u sock 0,8 0t0 91330 protocol: TCP guerrilla 27561 2749 guser 4u a_inode 0,11 0 7050 [eventpoll] guerrilla 27561 2749 guser 5u sock 0,8 0t0 85889 protocol: TCP guerrilla 27561 2749 guser 6u sock 0,8 0t0 89697 protocol: TCP guerrilla 27561 2749 guser 7u sock 0,8 0t0 93198 protocol: TCP guerrilla 27561 2749 guser 8u sock 0,8 0t0 93199 protocol: TCP ... guerrilla 27561 2749 guser 251u sock 0,8 0t0 89749 protocol: TCP guerrilla 27561 2749 guser 252u sock 0,8 0t0 89750 protocol: TCP guerrilla 27561 2749 guser 253u sock 0,8 0t0 93266 protocol: TCP guerrilla 27561 2749 guser 254w REG 253,1 0 268596 /var/log/guerrilla/server.log guerrilla 27561 2749 guser 255u IPv4 89751 0t0 TCP localhost:2525 (LISTEN) guerrilla 27561 2749 guser 256w REG 253,1 498328 268597 /var/log/guerrilla/main.log guerrilla 27561 2749 guser 257u IPv6 93270 0t0 TCP :smtp (LISTEN) guerrilla 27561 2749 guser 258u IPv4 12271306 0t0 TCP localhost:44036->localhost:mysql (ESTABLISHED) guerrilla 27561 2749 guser 259u IPv4 12271356 0t0 TCP localhost:44064->localhost:mysql (ESTABLISHED) guerrilla 27561 2749 guser 260u IPv4 12394687 0t0 TCP localhost:44320->localhost:mysql (ESTABLISHED) ... guerrilla 27561 2749 guser 470u IPv4 12394997 0t0 TCP localhost:44518->localhost:mysql (ESTABLISHED) guerrilla 27561 2749 guser 471u IPv4 12394991 0t0 TCP localhost:44512->localhost:mysql (ESTABLISHED) guerrilla 27561 2750 guser cwd DIR 253,1 4096 267024 /home/guser guerrilla 27561 2750 guser rtd DIR 253,1 4096 2 / guerrilla 27561 2750 guser txt REG 253,1 15208236 17 /usr/local/bin/guerrillad guerrilla 27561 2750 guser mem REG 253,1 1868984 1295 /lib/x86_64-linux-gnu/libc-2.23.so guerrilla 27561 2750 guser mem REG 253,1 138696 1382 /lib/x86_64-linux-gnu/libpthread-2.23.so guerrilla 27561 2750 guser mem REG 253,1 162632 1271 /lib/x86_64-linux-gnu/ld-2.23.so guerrilla 27561 2750 guser 0r CHR 1,3 0t0 6 /dev/null guerrilla 27561 2750 guser 1w REG 253,1 20721 268593 /var/log/guerrilla/daemon.log guerrilla 27561 2750 guser 2w REG 253,1 20721 268593 /var/log/guerrilla/daemon.log guerrilla 27561 2750 guser 3u sock 0,8 0t0 91330 protocol: TCP guerrilla 27561 2750 guser 4u a_inode 0,11 0 7050 [eventpoll] guerrilla 27561 2750 guser 5u sock 0,8 0t0 85889 protocol: TCP guerrilla 27561 2750 guser 6u sock 0,8 0t0 89697 protocol: TCP guerrilla 27561 2750 guser 7u sock 0,8 0t0 93198 protocol: TCP ... guerrilla 27561 2750 guser 251u sock 0,8 0t0 89749 protocol: TCP guerrilla 27561 2750 guser 252u sock 0,8 0t0 89750 protocol: TCP guerrilla 27561 2750 guser 253u sock 0,8 0t0 93266 protocol: TCP guerrilla 27561 2750 guser 254w REG 253,1 0 268596 /var/log/guerrilla/server.log guerrilla 27561 2750 guser 255u IPv4 89751 0t0 TCP localhost:2525 (LISTEN) guerrilla 27561 2750 guser 256w REG 253,1 498328 268597 /var/log/guerrilla/main.log guerrilla 27561 2750 guser 257u IPv6 93270 0t0 TCP :smtp (LISTEN) guerrilla 27561 2750 guser 258u IPv4 12271306 0t0 TCP localhost:44036->localhost:mysql (ESTABLISHED) guerrilla 27561 2750 guser 259u IPv4 12271356 0t0 TCP localhost:44064->localhost:mysql (ESTABLISHED) ... guerrilla 27561 2750 guser 469u IPv4 12394986 0t0 TCP localhost:44510->localhost:mysql (ESTABLISHED) guerrilla 27561 2750 guser 470u IPv4 12394997 0t0 TCP localhost:44518->localhost:mysql (ESTABLISHED) guerrilla 27561 2750 guser 471u IPv4 12394991 0t0 TCP localhost:44512->localhost:mysql (ESTABLISHED) guerrilla 27561 3387 guser cwd DIR 253,1 4096 267024 /home/guser guerrilla 27561 3387 guser rtd DIR 253,1 4096 2 / guerrilla 27561 3387 guser txt REG 253,1 15208236 17 /usr/local/bin/guerrillad guerrilla 27561 3387 guser mem REG 253,1 1868984 1295 /lib/x86_64-linux-gnu/libc-2.23.so guerrilla 27561 3387 guser mem REG 253,1 138696 1382 /lib/x86_64-linux-gnu/libpthread-2.23.so guerrilla 27561 3387 guser mem REG 253,1 162632 1271 /lib/x86_64-linux-gnu/ld-2.23.so guerrilla 27561 3387 guser 0r CHR 1,3 0t0 6 /dev/null guerrilla 27561 3387 guser 1w REG 253,1 20721 268593 /var/log/guerrilla/daemon.log guerrilla 27561 3387 guser 2w REG 253,1 20721 268593 /var/log/guerrilla/daemon.log guerrilla 27561 3387 guser 3u sock 0,8 0t0 91330 protocol: TCP guerrilla 27561 3387 guser 4u a_inode 0,11 0 7050 [eventpoll] guerrilla 27561 3387 guser 5u sock 0,8 0t0 85889 protocol: TCP guerrilla 27561 3387 guser 6u sock 0,8 0t0 89697 protocol: TCP guerrilla 27561 3387 guser 7u sock 0,8 0t0 93198 protocol: TCP ... guerrilla 27561 3387 guser 252u sock 0,8 0t0 89750 protocol: TCP guerrilla 27561 3387 guser 253u sock 0,8 0t0 93266 protocol: TCP guerrilla 27561 3387 guser 254w REG 253,1 0 268596 /var/log/guerrilla/server.log guerrilla 27561 3387 guser 255u IPv4 89751 0t0 TCP localhost:2525 (LISTEN) guerrilla 27561 3387 guser 256w REG 253,1 498328 268597 /var/log/guerrilla/main.log guerrilla 27561 3387 guser 257u IPv6 93270 0t0 TCP *:smtp (LISTEN) guerrilla 27561 3387 guser 258u IPv4 12271306 0t0 TCP localhost:44036->localhost:mysql (ESTABLISHED) guerrilla 27561 3387 guser 259u IPv4 12271356 0t0 TCP localhost:44064->localhost:mysql (ESTABLISHED) guerrilla 27561 3387 guser 260u IPv4 12394687 0t0 TCP localhost:44320->localhost:mysql (ESTABLISHED) ... guerrilla 27561 3387 guser 470u IPv4 12394997 0t0 TCP localhost:44518->localhost:mysql (ESTABLISHED) guerrilla 27561 3387 guser 471u IPv4 12394991 0t0 TCP localhost:44512->localhost:mysql (ESTABLISHED) guerrilla 27561 3692 guser cwd DIR 253,1 4096 267024 /home/guser guerrilla 27561 3692 guser rtd DIR 253,1 4096 2 / guerrilla 27561 3692 guser txt REG 253,1 15208236 17 /usr/local/bin/guerrillad guerrilla 27561 3692 guser mem REG 253,1 1868984 1295 /lib/x86_64-linux-gnu/libc-2.23.so guerrilla 27561 3692 guser mem REG 253,1 138696 1382 /lib/x86_64-linux-gnu/libpthread-2.23.so guerrilla 27561 3692 guser mem REG 253,1 162632 1271 /lib/x86_64-linux-gnu/ld-2.23.so guerrilla 27561 3692 guser 0r CHR 1,3 0t0 6 /dev/null guerrilla 27561 3692 guser 1w REG 253,1 20721 268593 /var/log/guerrilla/daemon.log guerrilla 27561 3692 guser 2w REG 253,1 20721 268593 /var/log/guerrilla/daemon.log guerrilla 27561 3692 guser 3u sock 0,8 0t0 91330 protocol: TCP guerrilla 27561 3692 guser 4u a_inode 0,11 0 7050 [eventpoll] guerrilla 27561 3692 guser 5u sock 0,8 0t0 85889 protocol: TCP ...

Ok, I will test working with less count of save_workers_size (I think, 16

  • this is a good starting number).

PS: maybe this is due to #184 https://github.com/flashmob/go-guerrilla/issues/184 ?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/flashmob/go-guerrilla/issues/186?email_source=notifications&email_token=AAE6MPZYXFQSGMN6J33LA33QHY3RVA5CNFSM4ITC35U2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD5XXX5A#issuecomment-527399924, or mute the thread https://github.com/notifications/unsubscribe-auth/AAE6MP4XUOKAKY24YIMG423QHY3RVANCNFSM4ITC35UQ .

lord-alfred commented 5 years ago

Found strange thing:

$ cat /proc/`cat /var/run/guerrillad/guerrillad.pid`/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             31784                31784                processes
Max open files            1024                 4096                 files
Max locked memory         65536                65536                bytes
Max address space         unlimited            unlimited            bytes
Max file locks            unlimited            unlimited            locks
Max pending signals       31784                31784                signals
Max msgqueue size         819200               819200               bytes
Max nice priority         0                    0
Max realtime priority     0                    0
Max realtime timeout      unlimited            unlimited            us

Open files for guerrillad process is limited by 1024 / 4096.

UPD: I think, its because I run guerrillad from systemd service (#165). This can be fixed with:

guerrillad_systemd_dir="/lib/systemd/system/guerrillad.service.d"
mkdir -p ${guerrillad_systemd_dir}
echo "[Service]" >${guerrillad_systemd_dir}/limit.conf
echo "LimitNOFILE=65535" >>${guerrillad_systemd_dir}/limit.conf
systemctl daemon-reload
sudo systemctl restart guerrillad

After that I see:

$ cat /proc/`cat /var/run/guerrillad/guerrillad.pid`/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             31784                31784                processes
Max open files            65535                65535                files
Max locked memory         65536                65536                bytes
Max address space         unlimited            unlimited            bytes
Max file locks            unlimited            unlimited            locks
Max pending signals       31784                31784                signals
Max msgqueue size         819200               819200               bytes
Max nice priority         0                    0
Max realtime priority     0                    0
Max realtime timeout      unlimited            unlimited            us
flashmob commented 5 years ago

That's a useful command!

What do you see if you su guser and run

ulimit -n

?

On Wed., 4 Sep. 2019, 02:41 Lord Alfred, notifications@github.com wrote:

Found strange thing:

$ cat /proc/cat /var/run/guerrillad/guerrillad.pid/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 31784 31784 processes Max open files 1024 4096 files Max locked memory 65536 65536 bytes Max address space unlimited unlimited bytes Max file locks unlimited unlimited locks Max pending signals 31784 31784 signals Max msgqueue size 819200 819200 bytes Max nice priority 0 0 Max realtime priority 0 0 Max realtime timeout unlimited unlimited us

Open files for guerrillad process is limited by 1024 / 4096.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/flashmob/go-guerrilla/issues/186?email_source=notifications&email_token=AAE6MP2QC5DMHTIGKS43EIDQH2OT3A5CNFSM4ITC35U2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD5Y7VXQ#issuecomment-527563486, or mute the thread https://github.com/notifications/unsubscribe-auth/AAE6MP4TR4TZLKKPYQJ2M6LQH2OT3ANCNFSM4ITC35UQ .

lord-alfred commented 5 years ago
fullusr@host:~$ sudo su guser
guser@host:/home/guser$ ulimit -n
65535
guser@host:/home/guser$ ulimit -a
core file size          (blocks, -c) 0
data seg size           (kbytes, -d) unlimited
scheduling priority             (-e) 0
file size               (blocks, -f) unlimited
pending signals                 (-i) 31784
max locked memory       (kbytes, -l) 64
max memory size         (kbytes, -m) unlimited
open files                      (-n) 65535
pipe size            (512 bytes, -p) 8
POSIX message queues     (bytes, -q) 819200
real-time priority              (-r) 0
stack size              (kbytes, -s) 8192
cpu time               (seconds, -t) unlimited
max user processes              (-u) 65535
virtual memory          (kbytes, -v) unlimited
file locks                      (-x) unlimited

Tonight there were no longer those errors in the log that I wrote in the first post.

I will observe the situation for several days and if everything goes well, I will close this issue.

lord-alfred commented 5 years ago

After these changes, there were no more such problems.