Using a Cron Job with the "sysctl -p" Command to Speed up Sites

celiac101

Well-Known Member
Dec 19, 2012
96
1
58
cPanel Access Level
Website Owner
I have been pulling my hair out to speed up a large forum site on my server. I've spent years tuning my server, and lots of money and time on speeding up the IPB Forum app. I've recently noticed that simply running this command, aside from any changes I make...I mean just running this without making ANY CentOS changes, speeds up my site by 5-10%, and decreases the TTFB latency:
sysctl -p

I am considering running this command on a cron job every 10 minutes because it does more to speed up my site than tons of other things I've tried.

What exactly does this command do? I know it will load network changes to CentOS, but it must do other things, perhaps it clears cached stuff? I do host my own DNS, could it clear that cache?

A cron job seems like an easy 5-10% speed gain, but are there any issues or concerns about doing that? What if the backup process is running when that command runs?

Any help or advice would be highly appreciated.
 

cPanelLauren

Product Owner
Staff member
Nov 14, 2017
13,296
1,252
313
Houston
Just running that command I can't see how it would really change anything. Here is the man page for sysctl:

Code:
SYSCTL(8)                                                      System Administration                                                     SYSCTL(8)

NAME
       sysctl - configure kernel parameters at runtime

SYNOPSIS
       sysctl [options] [variable[=value]] [...]
       sysctl -p [file or regexp] [...]

DESCRIPTION
       sysctl is used to modify kernel parameters at runtime.  The parameters available are those listed under /proc/sys/.  Procfs is required for
       sysctl support in Linux.  You can use sysctl to both read and write sysctl data.

PARAMETERS
       variable
              The name of a key to read from.  An example is kernel.ostype.  The '/' separator is also accepted in place of a '.'.

       variable=value
              To set a key, use the form variable=value where variable is the key and value is the value to set it  to.   If  the  value  contains
              quotes or characters which are parsed by the shell, you may need to enclose the value in double quotes.  This requires the -w param‐
              eter to use.
Code:
   -p[FILE], --load[=FILE]
              Load in sysctl settings from the file specified or /etc/sysctl.conf if none given.  Specifying - as filename means reading data from
              standard  input.   Using  this  option will mean arguments to sysctl are files, which are read in the order they are specified.  The
              file argument may be specified as regular expression.
Are you loading specific settings from a certain file?
 

celiac101

Well-Known Member
Dec 19, 2012
96
1
58
cPanel Access Level
Website Owner
Yes, it loads settings that I've tweaked in /etc/sysctl.conf
Code:
net.ipv4.tcp_wmem=4096 12582912 16777216
net.ipv4.tcp_rmem=4096 12582912 16777216
net.core.rmem_max=16777216
net.core.wmem_max=16777216
net.ipv4.tcp_fin_timeout = 30
net.ipv4.tcp_tw_recycle = 1
net.ipv4.tcp_tw_reuse = 1
vm.overcommit_memory = 1
fs.file-max = 2097152
net.core.netdev_max_backlog = 131070
net.core.somaxconn = 131070
net.ipv4.tcp_max_syn_backlog = 3240000
net.ipv4.tcp_max_tw_buckets = 1440000
net.ipv4.tcp_window_scaling = 1
vm.swappiness = 30
The settings are already correctly running when I run the "sysctl -p" command, I have verified this, which is why I find this so strange. I have confirmed this speed increase many times over, which is what led me to this quest to discover what else this command could be doing: sysctl -p

Hopefully I've set the cron job up correctly in my /var/spool/cron/root file:

SHELL="/bin/bash"
*/15 * * * * sysctl -p >/dev/null 2>&1

I suspect it must clear out a cache somewhere with the old settings, and this somehow speeds things up. I am no server expert, but can testify that this command results in a site speed increase.
 

celiac101

Well-Known Member
Dec 19, 2012
96
1
58
cPanel Access Level
Website Owner
Would this be the proper way to set up the cron job? I am not sure if it is working the same as when run on the command line:
SHELL="/bin/bash"
*/15 * * * * sysctl -p >/dev/null 2>&1