歡迎您光臨本站 註冊首頁

WEB伺服器反應極度緩慢

←手機掃碼閱讀     火星人 @ 2014-03-04 , reply:0

WEB伺服器反應極度緩慢

嘗試用LINUX搭建了一個WEB伺服器(至強 3G 2個,2G內存,主要跑http和mysql),但發現訪問伺服器極度緩慢,網頁打不開,TOP結果如下,請大家幫我看看是什麼原因:
top - 16:42:46 up  1:30,  2 users,  load average: 563.32, 300.05, 179.08
Tasks: 2626 total, 204 running, 2422 sleeping,   0 stopped,   0 zombie
Cpu(s):  0.3%us, 88.8%sy,  0.0%ni,  0.0%id, 10.3%wa,  0.1%hi,  0.5%si,  0.0%st
Mem:   2075288k total,  2025492k used,    49796k free,     4636k buffers
Swap:  2096440k total,  1259804k used,   836636k free,    55600k cached

  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND
  192 root      12  -5     0    0    0 R   26  0.0   6:01.38 kswapd0
4738 mysql     16   0 1742m 352m 2236 R   20 17.4  45:46.25 mysqld
6690 apache    16   0 59068 3928 1472 R    2  0.2   0:03.79 httpd
6765 apache    16   0 59068 3896 1472 S    2  0.2   0:00.68 httpd
7301 apache    16   0 59068 3968 1508 S    2  0.2   0:01.23 httpd
7242 apache    16   0 60156 5288 2772 D    2  0.3   0:01.16 httpd
4334 apache    16   0 60284 5964 2688 D    2  0.3   0:00.90 httpd
4584 apache    16   0 59068 3904 1472 R    2  0.2   0:06.47 httpd
6315 apache    16   0 60156 5524 2540 R    2  0.3   0:03.61 httpd
6907 apache    16   0 59952 5396 2740 R    2  0.3   0:00.92 httpd
4072 apache    16   0 60164 5556 2732 S    2  0.3   0:06.22 httpd
6574 apache    16   0 59068 3896 1472 D    2  0.2   0:01.03 httpd
3615 apache    16   0 60156 4892 2540 R    2  0.2   0:00.99 httpd
4417 apache    16   0 60284 6376 2856 R    2  0.3   0:02.29 httpd
4767 apache    16   0 60284 5344 2688 D    2  0.3   0:01.12 httpd
6229 apache    16   0 60156 5396 2736 R    2  0.3   0:05.25 httpd
6650 apache    16   0 59068 3896 1472 R    2  0.2   0:00.97 httpd

從CPU看,好象負載也不是很大,但就是不知道什麼原因反應緩慢。有知道請指點,謝謝。如果此時PING伺服器的話,回應時間很短,

[ 本帖最後由 微型計算機 於 2008-6-14 17:09 編輯 ]
《解決方案》

我的HTTPD.CONF文件內容如下:


ServerTokens OS

ServerRoot "/etc/httpd"

PidFile run/httpd.pid

Timeout 120

KeepAlive Off

MaxKeepAliveRequests 100

KeepAliveTimeout 15


<IfModule prefork.c>
StartServers       8
MinSpareServers   25
MaxSpareServers   50
ServerLimit      50000
MaxClients       30000
MaxRequestsPerChild  10000
</IfModule>

<IfModule worker.c>
StartServers         2
MaxClients         150
MinSpareThreads     25
MaxSpareThreads     75
ThreadsPerChild     25
MaxRequestsPerChild  0
</IfModule>

Listen 80

LoadModule auth_basic_module modules/mod_auth_basic.so
LoadModule auth_digest_module modules/mod_auth_digest.so
LoadModule authn_file_module modules/mod_authn_file.so
LoadModule authn_alias_module modules/mod_authn_alias.so
LoadModule authn_anon_module modules/mod_authn_anon.so
LoadModule authn_dbm_module modules/mod_authn_dbm.so
LoadModule authn_default_module modules/mod_authn_default.so
LoadModule authz_host_module modules/mod_authz_host.so
LoadModule authz_user_module modules/mod_authz_user.so
LoadModule authz_owner_module modules/mod_authz_owner.so
LoadModule authz_groupfile_module modules/mod_authz_groupfile.so
LoadModule authz_dbm_module modules/mod_authz_dbm.so
LoadModule authz_default_module modules/mod_authz_default.so
LoadModule ldap_module modules/mod_ldap.so
LoadModule authnz_ldap_module modules/mod_authnz_ldap.so
LoadModule include_module modules/mod_include.so
LoadModule log_config_module modules/mod_log_config.so
LoadModule logio_module modules/mod_logio.so
LoadModule env_module modules/mod_env.so
LoadModule ext_filter_module modules/mod_ext_filter.so
LoadModule mime_magic_module modules/mod_mime_magic.so
LoadModule expires_module modules/mod_expires.so
LoadModule deflate_module modules/mod_deflate.so
LoadModule headers_module modules/mod_headers.so
LoadModule usertrack_module modules/mod_usertrack.so
LoadModule setenvif_module modules/mod_setenvif.so
LoadModule mime_module modules/mod_mime.so
LoadModule dav_module modules/mod_dav.so
LoadModule status_module modules/mod_status.so
LoadModule autoindex_module modules/mod_autoindex.so
LoadModule info_module modules/mod_info.so
LoadModule dav_fs_module modules/mod_dav_fs.so
LoadModule vhost_alias_module modules/mod_vhost_alias.so
LoadModule negotiation_module modules/mod_negotiation.so
LoadModule dir_module modules/mod_dir.so
LoadModule actions_module modules/mod_actions.so
LoadModule speling_module modules/mod_speling.so
LoadModule userdir_module modules/mod_userdir.so
LoadModule alias_module modules/mod_alias.so
LoadModule rewrite_module modules/mod_rewrite.so
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_balancer_module modules/mod_proxy_balancer.so
LoadModule proxy_ftp_module modules/mod_proxy_ftp.so
LoadModule proxy_http_module modules/mod_proxy_http.so
LoadModule proxy_connect_module modules/mod_proxy_connect.so
LoadModule cache_module modules/mod_cache.so
LoadModule suexec_module modules/mod_suexec.so
LoadModule disk_cache_module modules/mod_disk_cache.so
LoadModule file_cache_module modules/mod_file_cache.so
LoadModule mem_cache_module modules/mod_mem_cache.so
LoadModule cgi_module modules/mod_cgi.so


Include conf.d/*.conf


User apache
Group apache


ServerAdmin root@localhost


UseCanonicalName Off

DocumentRoot "/www/html/"

<Directory />
    Options FollowSymLinks
    AllowOverride None
</Directory>


<Directory "/www/html">

    Options Indexes FollowSymLinks

    AllowOverride None

    Order allow,deny
    Allow from all

</Directory>

<IfModule mod_userdir.c>
    UserDir disable


</IfModule>


DirectoryIndex index.php index.html index.html.var

AccessFileName .htaccess

<Files ~ "^\.ht">
    Order allow,deny
    Deny from all
</Files>

TypesConfig /etc/mime.types

DefaultType text/plain

<IfModule mod_mime_magic.c>
    MIMEMagicFile conf/magic
</IfModule>

HostnameLookups Off



ErrorLog logs/error_log

LogLevel warn

LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%h %l %u %t \"%r\" %>s %b" common
LogFormat "%{Referer}i -> %U" referer
LogFormat "%{User-agent}i" agent




CustomLog logs/access_log combined

ServerSignature On

Alias /icons/ "/www/icons/"

<Directory "/www/icons">
    Options Indexes MultiViews
    AllowOverride None
    Order allow,deny
    Allow from all
</Directory>

<IfModule mod_dav_fs.c>
    DAVLockDB /var/lib/dav/lockdb
</IfModule>

ScriptAlias /cgi-bin/ "/www/cgi-bin/"

<Directory "/www/cgi-bin">
    AllowOverride None
    Options None
    Order allow,deny
    Allow from all
</Directory>



IndexOptions FancyIndexing VersionSort NameWidth=* HTMLTable

AddIconByEncoding (CMP,/icons/compressed.gif) x-compress x-gzip

AddIconByType (TXT,/icons/text.gif) text/*
AddIconByType (IMG,/icons/image2.gif) image/*
AddIconByType (SND,/icons/sound2.gif) audio/*
AddIconByType (VID,/icons/movie.gif) video/*

AddIcon /icons/binary.gif .bin .exe
AddIcon /icons/binhex.gif .hqx
AddIcon /icons/tar.gif .tar
AddIcon /icons/world2.gif .wrl .wrl.gz .vrml .vrm .iv
AddIcon /icons/compressed.gif .Z .z .tgz .gz .zip
AddIcon /icons/a.gif .ps .ai .eps
AddIcon /icons/layout.gif .html .shtml .htm .pdf
AddIcon /icons/text.gif .txt
AddIcon /icons/c.gif .c
AddIcon /icons/p.gif .pl .py
AddIcon /icons/f.gif .for
AddIcon /icons/dvi.gif .dvi
AddIcon /icons/uuencoded.gif .uu
AddIcon /icons/script.gif .conf .sh .shar .csh .ksh .tcl
AddIcon /icons/tex.gif .tex
AddIcon /icons/bomb.gif core

AddIcon /icons/back.gif ..
AddIcon /icons/hand.right.gif README
AddIcon /icons/folder.gif ^^DIRECTORY^^
AddIcon /icons/blank.gif ^^BLANKICON^^

DefaultIcon /icons/unknown.gif


ReadmeName README.html
HeaderName HEADER.html


AddLanguage ca .ca
AddLanguage cs .cz .cs
AddLanguage da .dk
AddLanguage de .de
AddLanguage el .el
AddLanguage en .en
AddLanguage eo .eo
AddLanguage es .es
AddLanguage et .et
AddLanguage fr .fr
AddLanguage he .he
AddLanguage hr .hr
AddLanguage it .it
AddLanguage ja .ja
AddLanguage ko .ko
AddLanguage ltz .ltz
AddLanguage nl .nl
AddLanguage nn .nn
AddLanguage no .no
AddLanguage pl .po
AddLanguage pt .pt
AddLanguage pt-BR .pt-br
AddLanguage ru .ru
AddLanguage sv .sv
AddLanguage zh-CN .zh-cn
AddLanguage zh-TW .zh-tw

LanguagePriority en ca cs da de el eo es et fr he hr it ja ko ltz nl nn no pl pt pt-BR ru sv zh-CN zh-TW

ForceLanguagePriority Prefer Fallback

AddDefaultCharset GB2312



AddType application/x-compress .Z
AddType application/x-gzip .gz .tgz



AddHandler type-map var

AddType text/html .shtml
AddOutputFilter INCLUDES .shtml




Alias /error/ "/www/error/"

<IfModule mod_negotiation.c>
<IfModule mod_include.c>
    <Directory "/www/error">
        AllowOverride None
        Options IncludesNoExec
        AddOutputFilter Includes html
        AddHandler type-map var
        Order allow,deny
        Allow from all
        LanguagePriority en es de fr
        ForceLanguagePriority Prefer Fallback
    </Directory>


</IfModule>
</IfModule>

BrowserMatch "Mozilla/2" nokeepalive
BrowserMatch "MSIE 4\.0b2;" nokeepalive downgrade-1.0 force-response-1.0
BrowserMatch "RealPlayer 4\.0" force-response-1.0
BrowserMatch "Java/1\.0" force-response-1.0
BrowserMatch "JDK/1\.0" force-response-1.0

BrowserMatch "Microsoft Data Access Internet Publishing Provider" redirect-carefully
BrowserMatch "MS FrontPage" redirect-carefully
BrowserMatch "^WebDrive" redirect-carefully
BrowserMatch "^WebDAVFS/1." redirect-carefully
BrowserMatch "^gnome-vfs/1.0" redirect-carefully
BrowserMatch "^XML Spy" redirect-carefully
BrowserMatch "^Dreamweaver-WebDAV-SCM1" redirect-carefully


NameVirtualHost *:80


<VirtualHost *:80>
    ServerAdmin xdzms@126.com
    DocumentRoot /www/ww2.xdzms.cn
    ServerName www.xdzms.cn
    ErrorLog logs/www.xdzms.cn-error_log
    CustomLog logs/www.xdzms.cn-access_log common
</VirtualHost>
《解決方案》

我的MY.CNF文件內容如下:


datadir=/var/lib/mysql

socket=/var/lib/mysql/mysql.sock

user=mysql
old_passwords=1

skip-locking

skip-name-resolve

skip-networking

skip-locking

skip-name-resolve

back_log = 384

max_allowed_packet = 64M

query_cache_size = 64M

query_cache_limit = 8M

connect_timeout=20

key_buffer_size=512M  

max_connections=100000

wait_timeout=10

read_buffer_size=32M

sort_buffer_size = 6M

myisam_sort_buffer_size=128M

join_buffer_size = 32M

table_cache=1024

thread_cache=64

default-character-set=gbk

thread_concurrency = 8




default-character-set =gbk





log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
《解決方案》

有88.8%的cpu是系統佔用的,看看系統在幹什麼
《解決方案》

我遇到過這樣的問題 是因為mysql 語句過於複雜 (對多個表關聯查詢) 把 語句優化下就好了
可以通過 查看mysql進程看是否有語句用時過長(如果有哪條語句一直在運行說明這條語句有問題)
《解決方案》

確定是MYSQL?
88.8%sy,  
表示系統等待設備驅動系統調用的比例高
罪魁禍首:效率低下的設備驅動程序,硬體故障導致的假中斷,
CPU速度慢或數量不足

用sar 1 5 等命令看下。是不是某個程序佔用了大量的資源,再作判斷。
《解決方案》

從top的結果來看
首先你有2400+的httpd進程,每個進程需要佔用一定的內存,這麼多的httpd導致內存用盡,然後系統大量使用swap,使用swap之後肯定會導致iowait。

1。你是否有這麼大的訪問量,導致有2400+的httpd併發,如果是,把apache改為worker模式,或者改用nginx,或者加2G內存
2。如果不是,那麼應該就是mysql有慢查詢(極其慢),導致httpd進程不能快速釋放

解釋的夠清楚了吧
如果還搞不定,找我

[火星人 ] WEB伺服器反應極度緩慢已經有625次圍觀

http://coctec.com/docs/service/show-post-29625.html