walkor / phpsocket.io

A server side alternative implementation of socket.io in PHP based on workerman.
2.3k stars 508 forks source link

Auto Restart Problem After High Socket Connection EROR: (Restart) #263

Closed seyitahmettanriver closed 3 years ago

seyitahmettanriver commented 3 years ago

After 200-600 connection, socket.io connection is automatically disconnected or the connection timeout occurs.

My server is very powerful and resource-intensive.

Server information: AMD Ryzen 5 3600 Hexa-Core 64GB DDR4 2 x 512 GB NVMe SSD

OS: CentOS 8.3 minimal

Panel: Plesk Panel

My site is serving over Nginx.

I am not using PHP 8.0 - 7.4 The problem occurs when there is a high link.

I think there is a connection limit somewhere. Automatically disconnects and restarts. Can you help with this ?

PUTY PHP STATUS Log:

ulimit -Hn : 262144 ulimit -Sn : 1024

https://i.ibb.co/9pzg34K/Screenshot-2.png

----------------------------------------------GLOBAL STATUS---------------------------------------------------- Workerman version:4.0.19 PHP version:8.0.3 start time:2021-03-26 16:59:38 run 0 days 0 hours load average: 3.97, 4, 4 event-loop:\Workerman\Events\Select 1 workers 1 processes worker_name exit_status exit_count PHPSocketIO 65280 2 ----------------------------------------------PROCESS STATUS--------------------------------------------------- pid memory listening worker_name connections send_fail timers total_request qps status 193868 10M socketIO://0.0.0.0:7005 PHPSocketIO 320 0 248 705 0 [idle] ----------------------------------------------PROCESS STATUS--------------------------------------------------- Summary 10M - - 320 0 248 705 0 [Summary]

seyitahmettanriver commented 3 years ago

Log:

2021-03-26 17:30:24 pid:195228 Worker[195228] process terminated with ERROR: E_ERROR "Allowed memory size of 134217728 bytes exhausted (tried to allocate 1056768 bytes) in /var/www/vhosts/mysite.com/httpdocs/vendor/workerman/workerman/Connection/TcpConnection.php on line 395"

walkor commented 3 years ago

ulimit -Sn : 1024 is too little. ulimit -Sn : 262144 is more reasonable. And please install event extension for php.

If the problem persists, try using the command strace -ttp pid (for example strace -ttp 193868) to see what happened to the process.

seyitahmettanriver commented 3 years ago

[root@server ]# ulimit -a
core file size          (blocks, -c) unlimited
data seg size           (kbytes, -d) unlimited
scheduling priority             (-e) 0
file size               (blocks, -f) unlimited
pending signals                 (-i) 256016
max locked memory       (kbytes, -l) 64
max memory size         (kbytes, -m) unlimited
open files                      (-n) 500000
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) 500000
virtual memory          (kbytes, -v) unlimited
file locks                      (-x) unlimited

Yesterday I raised all the aforementioned values. However, after 9 to 10 hours, the connection was not interrupted. But there was an extreme delay and slowness.

After a certain period of time, the number of rams and connections increases. Therefore, the socket server cannot respond.

Online number on the site: Between 150 - 250.

[root@server ]# /opt/plesk/php/7.4/bin/php /var/www/vhosts/mysite.com/httpdocs/mysite/socket.server.php status
Workerman[/var/www/vhosts/mysite.com/httpdocs/mysite/socket.server.php status] status
----------------------------------------------GLOBAL STATUS----------------------------------------------------
Workerman version:4.0.19          PHP version:7.4.16
start time:2021-03-28 01:16:42   run 0 days 10 hours
load average: 5.82, 6, 5         event-loop:\Workerman\Events\Select
1 workers       1 processes
worker_name  exit_status      exit_count
PHPSocketIO  65280            1
----------------------------------------------PROCESS STATUS---------------------------------------------------
pid     memory  listening               worker_name  connections send_fail timers  total_request qps    status
96215   257M    socketIO://0.0.0.0:7005 PHPSocketIO  44887       1706      122     646846        0      [idle]
----------------------------------------------PROCESS STATUS---------------------------------------------------
Summary 257M    -                       -            44887       1706      122     646846        0      [Summary]
walkor commented 3 years ago

Please install event extension.

seyitahmettanriver commented 3 years ago

Please install event extension.

I am using a Plesk panel. I tried to install "event" extension on php 7.4 version but it failed.

The commands I use are:

/opt/plesk/php/7.4/bin/pecl install event
echo 'extension=mcrypt.so' > /opt/plesk/php/7.4/etc/php.d/mcrypt.ini
seyitahmettanriver commented 3 years ago

7.4.16 FPM https://prnt.sc/10y1gup

seyitahmettanriver commented 3 years ago

PHP 7.4 Event Installation on Plesk Panel: During installation, write "openssl installation prefix [no]:" no and press enter. After installation, restart the server 1 time. Then, when you run the script with PHP 7.4, all the problems will be solved.

You can give these commands via PUTTY:

/opt/plesk/php/7.4/bin/pecl install event
 echo 'extension=mcrypt.so' > /opt/plesk/php/7.4/etc/php.d/mcrypt.ini
 For phpize and libevent
sudo apt update
sudo apt install php7.3-dev libevent-dev
sudo update-alternatives --set php-config /usr/bin/php-config7.3
sudo update-alternatives --set phpize /usr/bin/phpize7.3
# sudo update-alternatives --set php /usr/bin/php7.3

# Install extensions
sudo pecl install ev
sudo pecl install event #  at the 'Include libevent OpenSSL support [yes] :' prompt type "no".

# Create configurations
echo 'extension=ev.so' | sudo tee /etc/php/7.3/mods-available/ev.ini
echo 'extension=event.so' | sudo tee /etc/php/7.3/mods-available/event.ini

# Create symlinks
sudo phpenmod -v 7.3 ev
sudo phpenmod -v 7.3 event

# Note: The libevent extension is unmaintained; consider to use the event extension instead.
# https://www.php.net/manual/en/intro.libevent.php

# Check modules are loaded
php -m | grep ev
# Note that for the webserver you need to check elsewhere as well.

# restore npm and node
sudo apt install libssl1.0-dev node-gyp nodejs-dev npm
sudo apt autoremove