-
Notifications
You must be signed in to change notification settings - Fork 976
Speed up your page
I will try to explain here the magic we use to try to make our pages load faster and handle thousands of requests.
Enabling these options will certainly make your site load faster, but the content presented may not be the most recent.
for example, you just upload a video, and you can already see the video in the video manager, but it still does not appear on the main page. Do not worry, YouPHPTube is on the back updating it and will display for you soon, we will prioritize the quick presentation, even if this is not the latest content.
Websites are generally viewed hundreds, thousands, or sometimes even millions of times per month. Normally, each time a browser requests a web page, the server has to do a bunch of complex (and time-consuming) calculations. But if you enable this plugin instead process every request you will serve static pages that expire in a specific amount of time, and then this page will be recreated.
The purpose of this is to minimize the distance between your visitors and your video files, a CDN stores a cached version of your content in multiple geographic locations.
To use a CDN please read this
https://github.com/DanielnetoDotCom/YouPHPTube/wiki/Using-CDN-for-Videos-Only
We use the apache xsend file to control every file access on our site, but for that, we have to check every time if your user has the proper right to access it. To avoid PHP to be querying on each file access (JS, CSS, Images, and videos) Disable the xsendfile.
To do this edit your .htaccess file and comment RewriteRule regarding xsendfile, so after the comment, you should have a configuration just like below
# It must be before image not found
<IfModule mod_xsendfile.c>
#RewriteRule ^videos/([A-Za-z0-9-_.]+)$ view/xsendfile.php?file=$1 [QSA]
</IfModule>
To enable this go to the CustomizeAdvanced plugin.
AsyncJobs will save some multiple database queries into a file in the cache directory.
It will save you queries and CPU but you will increase your file system IO
With this, you will enable the Asynchronous mode in many of our functions, so those Asynchronous functions do not block your page to be loaded. Every synchronous call waits and blocks for your results to come back. This is just a sleeping thread and wasted computation. but this AsyncJobs will serve you with the latest content and then recreate it on the background, so the next request you will have a more fresh content.
Asynchronous requests are the way to scale to thousands of concurrent users.
The Apache2Buddy script, similar to MySQLTuner, reviews your Apache setup, and makes suggestions based on your Apache process memory and overall RAM. Although it is a fairly basic program, that focuses on the MaxClients directive, Apache2Buddy is useful. You can run the script with the following command:
curl -sL https://raw.githubusercontent.com/richardforth/apache2buddy/master/apache2buddy.pl | sudo perl
and edit this file to follow the apache2buddy recommendations
nano /etc/apache2/mods-enabled/mpm_prefork.conf
Here is a sample configurationm the apache2buddy will let you know the MaxRequestWorkers value
<IfModule mpm_prefork_module>
ServerLimit 5000
StartServers 5
MinSpareServers 5
MaxSpareServers 10
MaxRequestWorkers 1500
MaxConnectionsPerChild 0
</IfModule>