WWBN / AVideo

Create Your Own Broadcast Network With AVideo Platform Open-Source. OAVP OVP
https://avideo.tube/AVideo_OpenSource
Other
1.91k stars 972 forks source link

Socket Server just keeps freezing the webpage #6885

Closed JoshWho closed 2 years ago

JoshWho commented 2 years ago

I think it is the socket server. The page just keeps getting harder to navigate always getting the waring saying page is unresponsive do you want to wait or exit.

JoshWho commented 2 years ago

apon inspection I see this in the console

Uncaught ReferenceError: webSiteRootURL is not defined
    at HTMLDocument.<anonymous> (script.js?cache=1654434748_1654434748:288:24)
    at e (jquery.min.js?cache=1653393647_1653434754:2:30038)
    at t (jquery.min.js?cache=1653393647_1653434754:2:30340)
JoshWho commented 2 years ago

the link to that file is

https://joshwho-cdn.com/plugin/YPTSocket/script.js?cache=1654434748_1654434748

JoshWho commented 2 years ago

I turned off the socket server plugin and now it is not doing the freeze thing anymore.

JoshWho commented 2 years ago

I can confirm I can now leave the tab to another tab with a video playing come back to it 3 minutes later and it is not frozen.

I can't do that when the socket plugin is running. When the Socket server plugin is enabled I try the same test and it freezes and I have to wait for it to unfreeze or click exit page

JoshWho commented 2 years ago

Is there a way to fully limit the socket plugin to just the live stream pages? Like only let the script run only on live video streams only.

Sitewide is a problem

JoshWho commented 2 years ago

My issue may be related to the cdn pulling the scripts through cloudflare, and cloudflare giving limits to sockets.

Once a socket disconnects from the client, the client has to wait for a connection to establish back, and that is what causes the whole webpage to freeze is the connection to the socket reconnecting.

GreenDragonTavern commented 2 years ago

@JoshWho what does ps aux | grep [p]hp show?

JoshWho commented 2 years ago
root@joshwhotv:~# ps aux | grep [p]hp
root      1773  0.0  0.1 656396 29884 ?        Ss   Jul15   0:03 php-fpm: master                                                                                                               process (/etc/php/7.4/fpm/php-fpm.conf)
root      1815  0.0  0.2 1538908 38244 ?       Ss   Jul15   0:03 php-fpm: master                                                                                                               process (/etc/php/7.2/fpm/php-fpm.conf)
root      1817  0.0  0.1 578044 24432 ?        Ss   Jul15   0:03 php-fpm: master                                                                                                               process (/etc/php/7.3/fpm/php-fpm.conf)
www-data  1915  0.0  0.0 580340 11948 ?        S    Jul15   0:00 php-fpm: pool w                                                                                                              ww
www-data  1916  0.0  0.0 580340 11948 ?        S    Jul15   0:00 php-fpm: pool w                                                                                                              ww
www-data  1919  0.0  0.0 658692 14268 ?        S    Jul15   0:00 php-fpm: pool w                                                                                                              ww
www-data  1920  0.0  0.0 658692 14268 ?        S    Jul15   0:00 php-fpm: pool w                                                                                                              ww
www-data  1929  0.0  0.0 1541204 14800 ?       S    Jul15   0:00 php-fpm: pool w                                                                                                              ww
www-data  1930  0.0  0.0 1541204 14800 ?       S    Jul15   0:00 php-fpm: pool w                                                                                                              ww
root     15429  0.0  0.2 331268 37284 ?        S    01:00   0:04 php /var/www/ht                                                                                                              ml/YouPHPTube/plugin/YPTSocket/serverCertbot.php
root     15499  0.0  0.0 187356  4012 ?        S    01:00   0:00 sudo nohup php                                                                                                               /var/www/html/YouPHPTube/plugin/YPTSocket/server.php
root     15500  1.6  0.3 356472 59096 ?        S    01:00  11:10 php /var/www/ht                                                                                                              ml/YouPHPTube/plugin/YPTSocket/server.php
You have new mail in /var/mail/root
GreenDragonTavern commented 2 years ago

My socket instance looks like this: root 1372 86.4 0.0 126412 52528 ? R 14:17 158:20 php /var/www/html/AVideo/plugin/YPTSocket/server.php

You have two instances of socket running, there should only be one. Try killing the sudo one and see what shakes out.

JoshWho commented 2 years ago

Ok I killed that we are now at

root@joshwhotv:~# ps aux | grep [p]hp
root      1773  0.0  0.1 656396 29884 ?        Ss   Jul15   0:03 php-fpm: master process (/etc/php/7.4/fpm/php-fpm.conf)
root      1815  0.0  0.2 1538908 38244 ?       Ss   Jul15   0:03 php-fpm: master process (/etc/php/7.2/fpm/php-fpm.conf)
root      1817  0.0  0.1 578044 24432 ?        Ss   Jul15   0:03 php-fpm: master process (/etc/php/7.3/fpm/php-fpm.conf)
www-data  1915  0.0  0.0 580340 11948 ?        S    Jul15   0:00 php-fpm: pool www
www-data  1916  0.0  0.0 580340 11948 ?        S    Jul15   0:00 php-fpm: pool www
www-data  1919  0.0  0.0 658692 14268 ?        S    Jul15   0:00 php-fpm: pool www
www-data  1920  0.0  0.0 658692 14268 ?        S    Jul15   0:00 php-fpm: pool www
www-data  1929  0.0  0.0 1541204 14800 ?       S    Jul15   0:00 php-fpm: pool www
www-data  1930  0.0  0.0 1541204 14800 ?       S    Jul15   0:00 php-fpm: pool www
root     15429  0.0  0.2 331268 37284 ?        S    01:00   0:04 php /var/www/html/YouPHPTube/plugin/YPTSocket/serverCertbot.php
root     15500  1.6  0.3 356472 59096 ?        S    01:00  11:10 php /var/www/html/YouPHPTube/plugin/YPTSocket/server.php
You have new mail in /var/mail/root

I want you to test this, come to my site here and let this vide play for a bit and go to another tab for a couple minutes then come back and tell me if the whole page is froze

https://www.joshwhotv.com/v/.SSE4

GreenDragonTavern commented 2 years ago

Opened three (3) tabs in addition to your link, no issue here. Also curious why serverCertbot.php is still running? That's a one and done cron job.

JoshWho commented 2 years ago

Good question. Not sure. I will keep checking overtime for the day before I close this. If it doesn't freeze up anymore than that was the issue was 2 ypt socket servers running.

GreenDragonTavern commented 2 years ago

I'd kill the certbot one too, has no business running as it should have closed long ago.

JoshWho commented 2 years ago

I killed the certbot one and now the socket server is disconnected

GreenDragonTavern commented 2 years ago

Weird, what does grep say now?

JoshWho commented 2 years ago
root@joshwhotv:~# ps aux | grep [p]hp
root      1773  0.0  0.1 656396 29884 ?        Ss   Jul15   0:03 php-fpm: master process (/etc/php/7.4/fpm/php-fpm.conf)
root      1815  0.0  0.2 1538908 38244 ?       Ss   Jul15   0:03 php-fpm: master process (/etc/php/7.2/fpm/php-fpm.conf)
root      1817  0.0  0.1 578044 24432 ?        Ss   Jul15   0:03 php-fpm: master process (/etc/php/7.3/fpm/php-fpm.conf)
www-data  1915  0.0  0.0 580340 11948 ?        S    Jul15   0:00 php-fpm: pool www
www-data  1916  0.0  0.0 580340 11948 ?        S    Jul15   0:00 php-fpm: pool www
www-data  1919  0.0  0.0 658692 14268 ?        S    Jul15   0:00 php-fpm: pool www
www-data  1920  0.0  0.0 658692 14268 ?        S    Jul15   0:00 php-fpm: pool www
www-data  1929  0.0  0.0 1541204 14800 ?       S    Jul15   0:00 php-fpm: pool www
www-data  1930  0.0  0.0 1541204 14800 ?       S    Jul15   0:00 php-fpm: pool www
You have new mail in /var/mail/root
JoshWho commented 2 years ago

Restarted it now show

root@joshwhotv:~# ps aux | grep [p]hp
root      1773  0.0  0.1 656396 29884 ?        Ss   Jul15   0:03 php-fpm: master process (/etc/php/7.4/fpm/php-fpm.conf)
root      1815  0.0  0.2 1538908 38244 ?       Ss   Jul15   0:03 php-fpm: master process (/etc/php/7.2/fpm/php-fpm.conf)
root      1817  0.0  0.1 578044 24432 ?        Ss   Jul15   0:03 php-fpm: master process (/etc/php/7.3/fpm/php-fpm.conf)
www-data  1915  0.0  0.0 580340 11948 ?        S    Jul15   0:00 php-fpm: pool www
www-data  1916  0.0  0.0 580340 11948 ?        S    Jul15   0:00 php-fpm: pool www
www-data  1919  0.0  0.0 658692 14268 ?        S    Jul15   0:00 php-fpm: pool www
www-data  1920  0.0  0.0 658692 14268 ?        S    Jul15   0:00 php-fpm: pool www
www-data  1929  0.0  0.0 1541204 14800 ?       S    Jul15   0:00 php-fpm: pool www
www-data  1930  0.0  0.0 1541204 14800 ?       S    Jul15   0:00 php-fpm: pool www
root     14722  0.0  0.0 187356  4124 pts/1    S    12:51   0:00 sudo nohup php /var/www/html/YouPHPTube/plugin/YPTSocket/server.php
root     14723  3.0  0.3 348844 50288 pts/1    S    12:51   0:00 php /var/www/html/YouPHPTube/plugin/YPTSocket/server.php
root     14765  0.0  0.0   4636   772 ?        Ss   12:52   0:00 /bin/sh -c php /var/www/html/YouPHPTube/plugin/Scheduler/run.php #Avideo Scheduler
root     14768 11.0  0.2 335652 37328 ?        S    12:52   0:00 php /var/www/html/YouPHPTube/plugin/Scheduler/run.php
JoshWho commented 2 years ago

there is the sudo one again. seems that automatically starts with the startup script

GreenDragonTavern commented 2 years ago

If you're root, no need for sudo on command line.

JoshWho commented 2 years ago

It was the copy script I didn't modify it before pasting

GreenDragonTavern commented 2 years ago

Highlight, Ctrl-C, then a right mouse click is sometimes in need of adjustment ;-)

JoshWho commented 2 years ago

Im talking about the one that shows on the debugger when it is disconnected.

GreenDragonTavern commented 2 years ago

No worries, was just kidding ya about the cut and paste. I troubleshoot as root to ensure sudo doesn't come into play. With that said, should only be one instance of AVideo socket per port.

JoshWho commented 2 years ago

Looks like it is running a lot smoother now. Im gonna have to check for that every reboot now until I can figure out why 2 starts up. I am gonna close this now.

GreenDragonTavern commented 2 years ago

If root is loading cron at boot, don't use sudo, not necessary.

JoshWho commented 2 years ago

It is doing it again

image

JoshWho commented 2 years ago

It is the socket server for sure. If this could just be used for the live stats page that would work better because the home page and video play page doesn't use it for how I have it setup.

GreenDragonTavern commented 2 years ago

Hmm...just put up a spanking new AVideo server, basically zero load. Socket at idle sucks up 4% of resources...100% of a single core. Something is amiss, agreed.

JoshWho commented 2 years ago

I just have the socket plugin turned off for now, it makes a huge difference.

GreenDragonTavern commented 2 years ago

Just got back to the house and going to run some simulations. Something is definitely up with socket interface. No way in hades does zero activity suck up cores for no reason, and this socket interface is hungry for NO REASON. Going to setup live stream for 30 minutes, attach 50 users and see what shakes out. Will post results of socket thereafter.

JoshWho commented 2 years ago

Looking forward to your findings

GreenDragonTavern commented 2 years ago

Jeez...15 users instantly did this! At 49% of which Sockets is almost ALL of a R630 Dual, 12 core bare metal box! Sockets is the kiss of death and thread KILLER! Box is at a slow CRAWL now. 50 users will easily kill it. SocketThreadKiller

JoshWho commented 2 years ago

My site has increased in speed with everything ever since I disabled it. Day and night difference.

GreenDragonTavern commented 2 years ago

The reason for sockets is just the opposite of what's happening. Have company and have to partake but later tonight will dig deeper into why this flavor of sockets KILLS THRAEADS at a fearsome rate. You are correct, sockets is UNUSABLE as it stands now and folks at AVideo better believe it's a reality. An R630 with compiled PHP events should handle hundreds of active viewers without breaking a sweat vs KILLING a BOX!

JoshWho commented 2 years ago

I agree, something wonky with it majorly. Shouldn't even notice it is running in the background. I see youtubes running and their page loads are blazing. Mine are now really fast after I disabled it. Super weird.

JoshWho commented 2 years ago

I hope it is solvable, I really like the features for the chat and live user count. Im sure there is other background stuff that is important too not running at the moment. Wow I am so amazed how fast my site is right now without it though.

JoshWho commented 2 years ago

@DanielnetoDotCom Check out my site tell me if you think it is way faster than ever before. This is with the socket plugin disabled.

I didn't know the socket server was hurting the performance that much and could explain why lot of people struggled with page loads on my site. Now every page loads super fast.

https://www.joshwhotv.com

DanielnetoDotCom commented 2 years ago

Hi, I think the socket is required to make it work properly. but definitely, it can be improved, but first I need to be able to see where the problem comes from.

@JoshWho are you saying if I leave a browser opened for 3 minutes on your page it will freeze?

is the problem on the client side or server side? if the browser freezes it seems to be a client-side issue.

if the CPU goes 100% it will be a server-side problem, what happens first, client or server?

JoshWho commented 2 years ago

All the users that was complaining about the site freezing all are saying it is working great now. In Fact it is working the best it has ever ran. Did u see how fast it is now?

Only difference was me shutting off the socket plugin.

GreenDragonTavern commented 2 years ago

@JoshWho for whatever reason, below did the trick, just did a live test afterwards. Socket is no longer eating up threads like before, and when live finished server load settled right back down to normal.

sudo git fetch --all && sudo git reset --hard origin/master sudo chown -R www-data:www-data /var/www/html/AVideo

JoshWho commented 2 years ago

Why the hard reset?

JoshWho commented 2 years ago

This is a huge factor in my site because It is live and is always under ddos so every bit of cpu is important here. The slightest mistake and my site is unstable and needs rebooted from remote

JoshWho commented 2 years ago

I have it back on for now for testing. Tell me if you see any slowdown. I did the chown and update

GreenDragonTavern commented 2 years ago

Have a live test on my social site: https://ourfreenation.org - Login is below, you'll see Tube on menu bar.

User: Demo Password: Demo123!

JoshWho commented 2 years ago

What I have done for now is limit the script to only work on Live Streams, Chat, and Live Links.

I am able to exclude it on sitewide using mod_pagespeed.

GreenDragonTavern commented 2 years ago

Don't know what to tell ya, check out my demo site, there's much more going on than just AVideo and runs fine. Have a live setup and be interested on how it works for you. Above is login info...

JoshWho commented 2 years ago

It worked great. I didnt see any lag. Is your site under any load or anything?

Just trying to compare. My server is using right now 57-58 % cpu at the moment because of a ddos but so far still stable.

GreenDragonTavern commented 2 years ago

Just upped it to 64 simulated users, AVideo, WP, Email and BBS clients all running on same box, at 27% load. Sockets is at 5% and that's normal while streaming live. Have a PowerEdge R630, dual CPU's, w/24 cores total.

GreenDragonTavern commented 2 years ago

256 moved it to 48% and sockets steady at 6%. Please give me 256 simultaneous live users :-)

DanielnetoDotCom commented 2 years ago

@GreenDragonTavern how do you simulate users?