Server load and reduction methods
- Posted on:
- Categories: Uncategorized
Introduction
Monitoring and reducing server load is essential to maintain performance and stability. This guide explains how to check server load and apply common methods to reduce it on a Linux-based server.
Prerequisites
- Root or SSH access to the server
- Basic knowledge of Linux commands
- Access to system monitoring tools
Implementation
Methods to check server load
1) Check the load using w command
bash12:~$ w
11:31:50 up 9:15, 8 users, load average: 0.81, 0.90, 0.91
11:31:50 up 9:15, 8 users, load average: 0.81, 0.90, 0.91
2) Check processes using top
bash12:~$ top -c
Tasks: 144 total, 2 running, 141 sleeping, 0 stopped, 1 zombie
Cpu(s): 28.7%us, 3.0%sy, 0.0%ni, 68.3%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st
Mem: 994376k total, 934952k used, 59424k free, 30228k buffers
Swap: 1389580k total, 22568k used, 1367012k free, 385788k cached
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
8835 hemanth. 20 0 411m 231m 31m R 24.2 23.9 35:23.63 /usr/local/firefox/firefox-bin
6486 root 20 0 117m 74m 9.9m S 5.6 7.6 24:29.87 /usr/X11R6/bin/X :0
7037 hemanth. 20 0 40340 18m 10m S 1.3 1.9 0:47.87 gnome-terminal
10025 hemanth. 20 0 5480 2212 1644 R 1.0 0.2 0:00.08 top -c
Tasks: 144 total, 2 running, 141 sleeping, 0 stopped, 1 zombie
Cpu(s): 28.7%us, 3.0%sy, 0.0%ni, 68.3%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st
Mem: 994376k total, 934952k used, 59424k free, 30228k buffers
Swap: 1389580k total, 22568k used, 1367012k free, 385788k cached
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
8835 hemanth. 20 0 411m 231m 31m R 24.2 23.9 35:23.63 /usr/local/firefox/firefox-bin
6486 root 20 0 117m 74m 9.9m S 5.6 7.6 24:29.87 /usr/X11R6/bin/X :0
7037 hemanth. 20 0 40340 18m 10m S 1.3 1.9 0:47.87 gnome-terminal
10025 hemanth. 20 0 5480 2212 1644 R 1.0 0.2 0:00.08 top -c
3) Check MySQL connections
root@host # mysqladmin proc
4) Check HTTP connections
root@host [/]# pidof httpd
30457 23992 23660 23659 23658 23657 23656 23655 10035 10028
30457 23992 23660 23659 23658 23657 23656 23655 10035 10028
5) Check uptime and load average
root@host [~]# uptime
14:09:07 up 159 days, 23:39, 2 users, load average: 0.30, 0.44, 0.44
14:09:07 up 159 days, 23:39, 2 users, load average: 0.30, 0.44, 0.44
Methods to reduce server load
1) netstat -plan | grep :80 | awk ‘{print $5}’ | cut -d: -f 1 | sort | uniq -c | sort -n
2) netstat -plan | grep :25 | awk ‘{print $5}’ | cut -d: -f 1 | sort | uniq -c | sort -n
3) pstree -paul
4) cd /tmp
5) rm -f dos-* sess_* .spamassassin*
6) find . -user nobody -exec rm -f ‘{}’ \;
7) ps -C exim -fH ewww
8) ps -C exim -fH eww |grep home
9) netstat -ntu | grep ‘:’ | awk ‘{print $5}’ | awk ‘{sub(“::ffff:”,””);print}’ | cut -f1 -d ‘:’ | sort | uniq -c | sort -n
10) mysqladmin proc |grep Sleep |awk {‘print $4’}|cut -d_ -f 1|sort|uniq -c|sort -nk 1
11) ps -C exim -fH ewww
12) for i in `ipcs -s | awk ‘{print $2}’`; do (ipcrm -s $i); done
13) for i in `mysqladmin proc |grep Sleep |cut -d ” “ -f 2`; do mysqladmin kill $i; done
14) exim -bp |grep “*** frozen ***” |awk ‘{print $3}’ |xargs exim -Mrm
15) exiqgrep -z -i | xargs exim -Mrm;exiqgrep -o 432000 -i | xargs exim -Mrm
2) netstat -plan | grep :25 | awk ‘{print $5}’ | cut -d: -f 1 | sort | uniq -c | sort -n
3) pstree -paul
4) cd /tmp
5) rm -f dos-* sess_* .spamassassin*
6) find . -user nobody -exec rm -f ‘{}’ \;
7) ps -C exim -fH ewww
8) ps -C exim -fH eww |grep home
9) netstat -ntu | grep ‘:’ | awk ‘{print $5}’ | awk ‘{sub(“::ffff:”,””);print}’ | cut -f1 -d ‘:’ | sort | uniq -c | sort -n
10) mysqladmin proc |grep Sleep |awk {‘print $4’}|cut -d_ -f 1|sort|uniq -c|sort -nk 1
11) ps -C exim -fH ewww
12) for i in `ipcs -s | awk ‘{print $2}’`; do (ipcrm -s $i); done
13) for i in `mysqladmin proc |grep Sleep |cut -d ” “ -f 2`; do mysqladmin kill $i; done
14) exim -bp |grep “*** frozen ***” |awk ‘{print $3}’ |xargs exim -Mrm
15) exiqgrep -z -i | xargs exim -Mrm;exiqgrep -o 432000 -i | xargs exim -Mrm
Conclusion
By regularly monitoring server load using commands like w, top, and uptime and applying cleanup and optimisation techniques, you can maintain better server performance and prevent overload issues.
Post Views: 49
