Open Litespeed: Tuning Server Settings Part 2
In OpenLiteSpeed Tuning Server Settings Part 1, I outlined some of the most common settings I usually tweak. Well in Part 2 decided to just automate the tuning with a shell script I wrote.
The shell script would usually be run in SSH telnet after initial OpenLiteSpeed installation. Feel free to modify it for your own needs.
Save contents in file named lsws_tweaks.sh and chmod +x it. By default, OpenLiteSpeed sets number of workers to just 1. This tuning script sets number of workers to 1/2 the number of cpu threads detected on your server. So if you have 8 cpu threads, this script will set number of workers to 8/2 = 4 workers.
#!/bin/bash ######################################### DESC='OpenLiteSpeed server tweaks' BYLINE='by George Liu (eva2000) vbtechsupport.com' ######################################### VER='0.0.1' DT=`date +"%d%m%y-%H%M%S"` RESTART='y' # restart server after tweaks ? LSWSCONFIG='/usr/local/lsws/conf/httpd_config.xml' USER='nobody' # change to your preferred user to run OLS GROUP='nobody' # change to your preferred group to run OLS ######################################### CPUS=$(grep "processor" /proc/cpuinfo |wc -l) CPUS=$(echo $CPUS/2 | bc) WORKERCHECK=$(grep '<httpdWorkers>' ${LSWSCONFIG}) ######################################### if [[ -z "$WORKERCHECK" ]]; then sed -i "4 i\ <httpdWorkers>${CPUS}<\/httpdWorkers>" ${LSWSCONFIG} fi ######################################### echo "-------------------------------------------------------------------" echo "$DESC" echo "$BYLINE" echo "-------------------------------------------------------------------" echo echo -n "Backup $LSWSCONFIG" cp -a $LSWSCONFIG ${LSWSCONFIG}_backup_${DT} echo " done" echo "Backup at ${LSWSCONFIG}_backup_${DT}" echo -n "General Tweaks" sed -i 's/<indexFiles>index.html<\/indexFiles>/<indexFiles>index.html index.php<\/indexFiles>/g' ${LSWSCONFIG} sed -i "s/<user>nobody<\/user>/<user>${USER}<\/user>/g" ${LSWSCONFIG} sed -i "s/<group>nobody<\/group>/<group>${GROUP}<\/group>/g" ${LSWSCONFIG} sed -i "s/<inMemBufSize>60M<\/inMemBufSize>/<inMemBufSize>120M<\/inMemBufSize>/g" ${LSWSCONFIG} echo " done" echo -n "Tuning Tweaks" sed -i "s/<smartKeepAlive>0<\/smartKeepAlive>/<smartKeepAlive>1<\/smartKeepAlive>/g" ${LSWSCONFIG} sed -i "s/<sndBufSize>0<\/sndBufSize>/<sndBufSize>65535<\/sndBufSize>/g" ${LSWSCONFIG} sed -i "s/<rcvBufSize>0<\/rcvBufSize>/<rcvBufSize>65535<\/rcvBufSize>/g" ${LSWSCONFIG} sed -i "s/<maxCachedFileSize>4096<\/maxCachedFileSize>/<maxCachedFileSize>16384<\/maxCachedFileSize>/g" ${LSWSCONFIG} sed -i "s/<totalInMemCacheSize>20M<\/totalInMemCacheSize>/<totalInMemCacheSize>40M<\/totalInMemCacheSize>/g" ${LSWSCONFIG} sed -i "s/<maxMMapFileSize>256K<\/maxMMapFileSize>/<maxMMapFileSize>512K<\/maxMMapFileSize>/g" ${LSWSCONFIG} sed -i "s/<totalMMapCacheSize>40M<\/totalMMapCacheSize>/<totalMMapCacheSize>80M<\/totalMMapCacheSize>/g" ${LSWSCONFIG} echo " done" echo -n "External App lsphp5 Tweaks" sed -i "s/<maxConns>35<\/maxConns>/<maxConns>50<\/maxConns>/g" ${LSWSCONFIG} sed -i "s/<env>PHP_LSAPI_CHILDREN=35<\/env>/<env>PHP_LSAPI_CHILDREN=50<\/env>/g" ${LSWSCONFIG} sed -i "s/<memSoftLimit>450M<\/memSoftLimit>/<memSoftLimit>900M<\/memSoftLimit>/g" ${LSWSCONFIG} sed -i "s/<memHardLimit>500M<\/memHardLimit>/<memHardLimit>1000M<\/memHardLimit>/g" ${LSWSCONFIG} sed -i "s/<procSoftLimit>300<\/procSoftLimit>/<procSoftLimit>1000<\/procSoftLimit>/g" ${LSWSCONFIG} sed -i "s/<procHardLimit>400<\/procHardLimit>/<procHardLimit>1200<\/procHardLimit>/g" ${LSWSCONFIG} echo " done" echo echo "-------------------------------------------------------------------" echo "Compare Tweaks vs Default settings" echo "-------------------------------------------------------------------" sdiff $LSWSCONFIG ${LSWSCONFIG}_backup_${DT} echo echo "-------------------------------------------------------------------" echo "Compare Tweaks vs Default settings" echo "-------------------------------------------------------------------" sdiff -s $LSWSCONFIG ${LSWSCONFIG}_backup_${DT} echo "-------------------------------------------------------------------" echo if [[ "$RESTART" = [yY] ]]; then service lsws restart fi exit |
Sample output from the script when ran includes a side by side comparison output for the tweaked vs default settings so you can see what was changed.
./lsws_tweaks.sh ------------------------------------------------------------------- OpenLiteSpeed server tweaks by George Liu (eva2000) vbtechsupport.com ------------------------------------------------------------------- Backup /usr/local/lsws/conf/httpd_config.xml done Backup at /usr/local/lsws/conf/httpd_config.xml_backup_250813-115116 General Tweaks done Tuning Tweaks done External App lsphp5 Tweaks done ------------------------------------------------------------------- Compare Tweaks vs Default settings ------------------------------------------------------------------- <?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?> <httpServerConfig> <httpServerConfig> <serverName>lshttpd</serverName> <serverName>lshttpd</serverName> <httpdWorkers>4</httpdWorkers> <httpdWorkers>4</httpdWorkers> <user>nobody</user> <user>nobody</user> <group>nobody</group> <group>nobody</group> <priority>0</priority> <priority>0</priority> <inMemBufSize>120M</inMemBufSize> | <inMemBufSize>60M</inMemBufSize> <swappingDir>/tmp/lshttpd/swap</swappingDir> <swappingDir>/tmp/lshttpd/swap</swappingDir> <autoRestart>1</autoRestart> <autoRestart>1</autoRestart> <autoFix503>1</autoFix503> <autoFix503>1</autoFix503> <mime>$SERVER_ROOT/conf/mime.properties</mime> <mime>$SERVER_ROOT/conf/mime.properties</mime> <showVersionNumber>0</showVersionNumber> <showVersionNumber>0</showVersionNumber> <adminRoot>$SERVER_ROOT/admin/</adminRoot> <adminRoot>$SERVER_ROOT/admin/</adminRoot> <logging> <logging> <log> <log> <fileName>$SERVER_ROOT/logs/error.log</fileName> <fileName>$SERVER_ROOT/logs/error.log</fileName> <logLevel>DEBUG</logLevel> <logLevel>DEBUG</logLevel> <debugLevel>0</debugLevel> <debugLevel>0</debugLevel> <rollingSize>10M</rollingSize> <rollingSize>10M</rollingSize> <enableStderrLog>1</enableStderrLog> <enableStderrLog>1</enableStderrLog> </log> </log> <accessLog> <accessLog> <fileName>$SERVER_ROOT/logs/access.log</fileName> <fileName>$SERVER_ROOT/logs/access.log</fileName> <rollingSize>10M</rollingSize> <rollingSize>10M</rollingSize> <keepDays>30</keepDays> <keepDays>30</keepDays> <compressArchive>0</compressArchive> <compressArchive>0</compressArchive> </accessLog> </accessLog> </logging> </logging> <indexFiles>index.html index.php</indexFiles> | <indexFiles>index.html</indexFiles> <expires> <expires> <enableExpires>1</enableExpires> <enableExpires>1</enableExpires> <expiresByType>image/*=A604800, text/css=A604800, applica <expiresByType>image/*=A604800, text/css=A604800, applica </expires> </expires> <tuning> <tuning> <eventDispatcher>best</eventDispatcher> <eventDispatcher>best</eventDispatcher> <SSLCryptoDevice>null</SSLCryptoDevice> <SSLCryptoDevice>null</SSLCryptoDevice> <maxConnections>2000</maxConnections> <maxConnections>2000</maxConnections> <maxSSLConnections>200</maxSSLConnections> <maxSSLConnections>200</maxSSLConnections> <connTimeout>300</connTimeout> <connTimeout>300</connTimeout> <maxKeepAliveReq>10000</maxKeepAliveReq> <maxKeepAliveReq>10000</maxKeepAliveReq> <smartKeepAlive>1</smartKeepAlive> | <smartKeepAlive>0</smartKeepAlive> <keepAliveTimeout>5</keepAliveTimeout> <keepAliveTimeout>5</keepAliveTimeout> <sndBufSize>65535</sndBufSize> | <sndBufSize>0</sndBufSize> <rcvBufSize>65535</rcvBufSize> | <rcvBufSize>0</rcvBufSize> <maxReqURLLen>8192</maxReqURLLen> <maxReqURLLen>8192</maxReqURLLen> <maxReqHeaderSize>16380</maxReqHeaderSize> <maxReqHeaderSize>16380</maxReqHeaderSize> <maxReqBodySize>2047M</maxReqBodySize> <maxReqBodySize>2047M</maxReqBodySize> <maxDynRespHeaderSize>8192</maxDynRespHeaderSize> <maxDynRespHeaderSize>8192</maxDynRespHeaderSize> <maxDynRespSize>2047M</maxDynRespSize> <maxDynRespSize>2047M</maxDynRespSize> <maxCachedFileSize>16384</maxCachedFileSize> | <maxCachedFileSize>4096</maxCachedFileSize> <totalInMemCacheSize>40M</totalInMemCacheSize> | <totalInMemCacheSize>20M</totalInMemCacheSize> <maxMMapFileSize>512K</maxMMapFileSize> | <maxMMapFileSize>256K</maxMMapFileSize> <totalMMapCacheSize>80M</totalMMapCacheSize> | <totalMMapCacheSize>40M</totalMMapCacheSize> <useSendfile>1</useSendfile> <useSendfile>1</useSendfile> <enableGzipCompress>1</enableGzipCompress> <enableGzipCompress>1</enableGzipCompress> <enableDynGzipCompress>1</enableDynGzipCompress> <enableDynGzipCompress>1</enableDynGzipCompress> <gzipCompressLevel>6</gzipCompressLevel> <gzipCompressLevel>6</gzipCompressLevel> <compressibleTypes>text/html</compressibleTypes> <compressibleTypes>text/html</compressibleTypes> <gzipAutoUpdateStatic>1</gzipAutoUpdateStatic> <gzipAutoUpdateStatic>1</gzipAutoUpdateStatic> <gzipStaticCompressLevel>6</gzipStaticCompressLevel> <gzipStaticCompressLevel>6</gzipStaticCompressLevel> <gzipMaxFileSize>1M</gzipMaxFileSize> <gzipMaxFileSize>1M</gzipMaxFileSize> <gzipMinFileSize>300</gzipMinFileSize> <gzipMinFileSize>300</gzipMinFileSize> </tuning> </tuning> <security> <security> <fileAccessControl> <fileAccessControl> <followSymbolLink>1</followSymbolLink> <followSymbolLink>1</followSymbolLink> <checkSymbolLink>0</checkSymbolLink> <checkSymbolLink>0</checkSymbolLink> <requiredPermissionMask>000</requiredPermissionMask> <requiredPermissionMask>000</requiredPermissionMask> <restrictedPermissionMask>000</restrictedPermissionMask <restrictedPermissionMask>000</restrictedPermissionMask </fileAccessControl> </fileAccessControl> <perClientConnLimit> <perClientConnLimit> <staticReqPerSec>0</staticReqPerSec> <staticReqPerSec>0</staticReqPerSec> <dynReqPerSec>0</dynReqPerSec> <dynReqPerSec>0</dynReqPerSec> <outBandwidth>0</outBandwidth> <outBandwidth>0</outBandwidth> <inBandwidth>0</inBandwidth> <inBandwidth>0</inBandwidth> <softLimit>10000</softLimit> <softLimit>10000</softLimit> <hardLimit>10000</hardLimit> <hardLimit>10000</hardLimit> <gracePeriod>15</gracePeriod> <gracePeriod>15</gracePeriod> <banPeriod>300</banPeriod> <banPeriod>300</banPeriod> </perClientConnLimit> </perClientConnLimit> <CGIRLimit> <CGIRLimit> <maxCGIInstances>20</maxCGIInstances> <maxCGIInstances>20</maxCGIInstances> <minUID>11</minUID> <minUID>11</minUID> <minGID>10</minGID> <minGID>10</minGID> <priority>0</priority> <priority>0</priority> <CPUSoftLimit>10</CPUSoftLimit> <CPUSoftLimit>10</CPUSoftLimit> <CPUHardLimit>50</CPUHardLimit> <CPUHardLimit>50</CPUHardLimit> <memSoftLimit>460M</memSoftLimit> <memSoftLimit>460M</memSoftLimit> <memHardLimit>470M</memHardLimit> <memHardLimit>470M</memHardLimit> <procSoftLimit>400</procSoftLimit> <procSoftLimit>400</procSoftLimit> <procHardLimit>450</procHardLimit> <procHardLimit>450</procHardLimit> </CGIRLimit> </CGIRLimit> <accessDenyDir> <accessDenyDir> <dir>/</dir> <dir>/</dir> <dir>/etc/*</dir> <dir>/etc/*</dir> <dir>/dev/*</dir> <dir>/dev/*</dir> <dir>$SERVER_ROOT/conf/*</dir> <dir>$SERVER_ROOT/conf/*</dir> <dir>$SERVER_ROOT/admin/conf/*</dir> <dir>$SERVER_ROOT/admin/conf/*</dir> </accessDenyDir> </accessDenyDir> <accessControl> <accessControl> <allow>ALL</allow> <allow>ALL</allow> </accessControl> </accessControl> </security> </security> <extProcessorList> <extProcessorList> <extProcessor> <extProcessor> <type>lsapi</type> <type>lsapi</type> <name>lsphp5</name> <name>lsphp5</name> <address>uds://tmp/lshttpd/lsphp5.sock</address> <address>uds://tmp/lshttpd/lsphp5.sock</address> <maxConns>50</maxConns> | <maxConns>35</maxConns> <env>PHP_LSAPI_MAX_REQUESTS=10000</env> <env>PHP_LSAPI_MAX_REQUESTS=10000</env> <env>PHP_LSAPI_CHILDREN=50</env> | <env>PHP_LSAPI_CHILDREN=35</env> <initTimeout>60</initTimeout> <initTimeout>60</initTimeout> <retryTimeout>0</retryTimeout> <retryTimeout>0</retryTimeout> <persistConn>1</persistConn> <persistConn>1</persistConn> <respBuffer>0</respBuffer> <respBuffer>0</respBuffer> <autoStart>1</autoStart> <autoStart>1</autoStart> <path>$SERVER_ROOT/fcgi-bin/lsphp5</path> <path>$SERVER_ROOT/fcgi-bin/lsphp5</path> <backlog>100</backlog> <backlog>100</backlog> <instances>1</instances> <instances>1</instances> <priority>0</priority> <priority>0</priority> <memSoftLimit>900M</memSoftLimit> | <memSoftLimit>450M</memSoftLimit> <memHardLimit>1000M</memHardLimit> | <memHardLimit>500M</memHardLimit> <procSoftLimit>1000</procSoftLimit> | <procSoftLimit>300</procSoftLimit> <procHardLimit>1200</procHardLimit> | <procHardLimit>400</procHardLimit> </extProcessor> </extProcessor> </extProcessorList> </extProcessorList> <scriptHandlerList> <scriptHandlerList> <scriptHandler> <scriptHandler> <suffix>php</suffix> <suffix>php</suffix> <type>lsapi</type> <type>lsapi</type> <handler>lsphp5</handler> <handler>lsphp5</handler> </scriptHandler> </scriptHandler> </scriptHandlerList> </scriptHandlerList> <railsDefaults> <railsDefaults> <railsEnv>1</railsEnv> <railsEnv>1</railsEnv> <maxConns>5</maxConns> <maxConns>5</maxConns> <env>LSAPI_MAX_REQS=1000</env> <env>LSAPI_MAX_REQS=1000</env> <env>LSAPI_MAX_IDLE=60</env> <env>LSAPI_MAX_IDLE=60</env> <initTimeout>60</initTimeout> <initTimeout>60</initTimeout> <retryTimeout>0</retryTimeout> <retryTimeout>0</retryTimeout> <pcKeepAliveTimeout>60</pcKeepAliveTimeout> <pcKeepAliveTimeout>60</pcKeepAliveTimeout> <respBuffer>0</respBuffer> <respBuffer>0</respBuffer> <backlog>50</backlog> <backlog>50</backlog> <runOnStartUp>1</runOnStartUp> <runOnStartUp>1</runOnStartUp> <extMaxIdleTime>300</extMaxIdleTime> <extMaxIdleTime>300</extMaxIdleTime> <priority>3</priority> <priority>3</priority> <memSoftLimit>550M</memSoftLimit> <memSoftLimit>550M</memSoftLimit> <memHardLimit>600M</memHardLimit> <memHardLimit>600M</memHardLimit> <procSoftLimit>1000</procSoftLimit> | <procSoftLimit>300</procSoftLimit> <procHardLimit>1200</procHardLimit> | <procHardLimit>400</procHardLimit> </railsDefaults> </railsDefaults> <virtualHostList> <virtualHostList> <virtualHost> <virtualHost> <name>Example</name> <name>Example</name> <vhRoot>$SERVER_ROOT/DEFAULT/</vhRoot> <vhRoot>$SERVER_ROOT/DEFAULT/</vhRoot> <configFile>$VH_ROOT/conf/vhconf.xml</configFile> <configFile>$VH_ROOT/conf/vhconf.xml</configFile> <allowSymbolLink>1</allowSymbolLink> <allowSymbolLink>1</allowSymbolLink> <enableScript>1</enableScript> <enableScript>1</enableScript> <restrained>1</restrained> <restrained>1</restrained> <setUIDMode>0</setUIDMode> <setUIDMode>0</setUIDMode> </virtualHost> </virtualHost> </virtualHostList> </virtualHostList> <listenerList> <listenerList> <listener> <listener> <name>Default</name> <name>Default</name> <address>*:8088</address> <address>*:8088</address> <secure>0</secure> <secure>0</secure> <vhostMapList> <vhostMapList> <vhostMap> <vhostMap> <vhost>Example</vhost> <vhost>Example</vhost> <domain>*</domain> <domain>*</domain> </vhostMap> </vhostMap> </vhostMapList> </vhostMapList> </listener> </listener> </listenerList> </listenerList> <vhTemplateList> <vhTemplateList> <vhTemplate> <vhTemplate> <name>centralConfigLog</name> <name>centralConfigLog</name> <templateFile>$SERVER_ROOT/conf/templates/ccl.xml</temp <templateFile>$SERVER_ROOT/conf/templates/ccl.xml</temp <listeners>Default</listeners> <listeners>Default</listeners> </vhTemplate> </vhTemplate> <vhTemplate> <vhTemplate> <name>PHP_SuEXEC</name> <name>PHP_SuEXEC</name> <templateFile>$SERVER_ROOT/conf/templates/phpsuexec.xml <templateFile>$SERVER_ROOT/conf/templates/phpsuexec.xml <listeners>Default</listeners> <listeners>Default</listeners> </vhTemplate> </vhTemplate> <vhTemplate> <vhTemplate> <name>EasyRailsWithSuEXEC</name> <name>EasyRailsWithSuEXEC</name> <templateFile>$SERVER_ROOT/conf/templates/rails.xml</te <templateFile>$SERVER_ROOT/conf/templates/rails.xml</te <listeners>Default</listeners> <listeners>Default</listeners> </vhTemplate> </vhTemplate> </vhTemplateList> </vhTemplateList> </httpServerConfig> </httpServerConfig> ------------------------------------------------------------------- Compare Tweaks vs Default settings ------------------------------------------------------------------- <inMemBufSize>120M</inMemBufSize> | <inMemBufSize>60M</inMemBufSize> <indexFiles>index.html index.php</indexFiles> | <indexFiles>index.html</indexFiles> <smartKeepAlive>1</smartKeepAlive> | <smartKeepAlive>0</smartKeepAlive> <sndBufSize>65535</sndBufSize> | <sndBufSize>0</sndBufSize> <rcvBufSize>65535</rcvBufSize> | <rcvBufSize>0</rcvBufSize> <maxCachedFileSize>16384</maxCachedFileSize> | <maxCachedFileSize>4096</maxCachedFileSize> <totalInMemCacheSize>40M</totalInMemCacheSize> | <totalInMemCacheSize>20M</totalInMemCacheSize> <maxMMapFileSize>512K</maxMMapFileSize> | <maxMMapFileSize>256K</maxMMapFileSize> <totalMMapCacheSize>80M</totalMMapCacheSize> | <totalMMapCacheSize>40M</totalMMapCacheSize> <maxConns>50</maxConns> | <maxConns>35</maxConns> <env>PHP_LSAPI_CHILDREN=50</env> | <env>PHP_LSAPI_CHILDREN=35</env> <memSoftLimit>900M</memSoftLimit> | <memSoftLimit>450M</memSoftLimit> <memHardLimit>1000M</memHardLimit> | <memHardLimit>500M</memHardLimit> <procSoftLimit>1000</procSoftLimit> | <procSoftLimit>300</procSoftLimit> <procHardLimit>1200</procHardLimit> | <procHardLimit>400</procHardLimit> <procSoftLimit>1000</procSoftLimit> | <procSoftLimit>300</procSoftLimit> <procHardLimit>1200</procHardLimit> | <procHardLimit>400</procHardLimit> ------------------------------------------------------------------- |