数据量变大可能是主因,有什么好办法知道从哪里入手改进
没有ssh界面, 网站在本地运行很快

解决方案 »

  1.   

    看看mysql的慢查询日志,或许有帮助
      

  2.   

    静态网站 YSLOW
    动态 就 优化缓存
      

  3.   

    这个问题的范围很大。从服务器负载,到后端后端优化,前端优化。很多方面,像你说的,首先要确定问题所在。df -h先看下磁盘使用情况,是否被占满。不知你用的什么web server,apache还是nginx还是其它。先用top检查服务器内存,cpu的使用率,如果是多核cpu请按1,观察每个核的状态。检查http连接数和php进程数量,
    ps- ef|grep -E "httpd|nginx"。检查配置文件的timeout时间,最大连接数等。看看是否超越你服务器负担,如果是设置问题,加大web server的连接数等,有针对性的优化他们。如果mysql的cpu占用率过高,show processlist或打开慢查日志,检查是什么sql导致,explain协助优化sql。看看你建立的索引是否都被成功使用到了。对于mysql的问题,我写过一个监控脚本。能够帮忙确定问题。分享给你 。
    dbMonitor.bash
    [code]
    #! /bin/bash#发送人
    mailfrom='[email protected]'#接收人
    mailto='[email protected]'#引入写log文件的函数库
    . ./lib/writelog.bash#cpu核心数量
    cpucount=16#cpu占用率阀值,根据核心数量来制定,我的cpu是16核,阀值定为500,也就是当cpu总占用率超过30%进行报警。
    threshold=500dbwithcpu=$(top -U mysql -b -n 1 | grep 'mysqld' | awk '{printf "%d",$9}')test -f message.txt && rm -f message.txt#根据cpu核心数量,取得cpu平均占用率。
    avgwithcpu=$(echo "scale=0;$dbwithcpu/$cpucount"|bc);infos="CPU core quantity:${cpucount}. mysqld current average occupancy rate:${avgwithcpu}% and current occupancy rate for total: ${dbwithcpu}% at $(date +'%Y-%m-%d %H:%M:%S')\n"
    infos=$infos"current sql list:\n"
    infos=$infos"--------------------------------\n\n"
    echo -e $infos > message.txt
    #写入log文件,这个你也可以不要。
    log_writer 'mysqld' "CPU core quantity:${cpucount}. mysqld current average occupancy rate:${avgwithcpu}% and current occupancy rate for total: ${dbwithcpu}% at $(date +'%Y-%m-%d %H:%M:%S')"if [ $dbwithcpu -ge $threshold ]; then
            /usr/local/webserver/mysql/bin/mysql -h127.0.0.1 -uroot -pmypassword -e"show full processlist;" | while read line 
            do
                    awk 'BEGIN{FS="\t"};{gsub(/\\t|\\n/,"",$8);print $8"\t(host:"$3" command:"$5" time:"$6" state:"$7")\n"}' >> message.txt
            done        mail -v -s "mysqld master monitor" "${mailto}" < message.txt -- -f "${mailfrom}"
    [/code]使用crontab,每5分钟跑一次。
    */5 * * * * /home/xxx/bin/dbMonitor.bash > /dev/null
    这个报警脚本,会每5分钟去top取一下mysql的cpu占用率,发现超过你设置的阀值后,就会发送邮件提醒你,并且把当时正在执行的sql打印出来。帮助你日后进行分析。
      

  4.   

    dbMonitor.bash#! /bin/bash#发送人
    mailfrom='[email protected]'#接收人
    mailto='[email protected]'#引入写log文件的函数库
    . ./lib/writelog.bash#cpu核心数量
    cpucount=16#cpu占用率阀值,根据核心数量来制定,我的cpu是16核,阀值定为500,也就是当cpu总占用率超过30%进行报警。
    threshold=500dbwithcpu=$(top -U mysql -b -n 1 | grep 'mysqld' | awk '{printf "%d",$9}')test -f message.txt && rm -f message.txt#根据cpu核心数量,取得cpu平均占用率。
    avgwithcpu=$(echo "scale=0;$dbwithcpu/$cpucount"|bc);infos="CPU core quantity:${cpucount}. mysqld current average occupancy rate:${avgwithcpu}% and current occupancy rate for total: ${dbwithcpu}% at $(date +'%Y-%m-%d %H:%M:%S')\n"
    infos=$infos"current sql list:\n"
    infos=$infos"--------------------------------\n\n"
    echo -e $infos > message.txt
    #写入log文件,这个你也可以不要。
    log_writer 'mysqld' "CPU core quantity:${cpucount}. mysqld current average occupancy rate:${avgwithcpu}% and current occupancy rate for total: ${dbwithcpu}% at $(date +'%Y-%m-%d %H:%M:%S')"if [ $dbwithcpu -ge $threshold ]; then
            /usr/local/webserver/mysql/bin/mysql -h127.0.0.1 -uroot -pmypassword -e"show full processlist;" | while read line 
            do
                    awk 'BEGIN{FS="\t"};{gsub(/\\t|\\n/,"",$8);print $8"\t(host:"$3" command:"$5" time:"$6" state:"$7")\n"}' >> message.txt
            done        mail -v -s "mysqld master monitor" "${mailto}" < message.txt -- -f "${mailfrom}"
      

  5.   

    后端排查问题大概就是这么个方向。
    前端优化也很重要也很复杂,但排查问题比后端较较但一些。你可以借助一些工具,比如firebug和chrome里面的分析工具。查看timeline。看看是哪些图片过大,或是js文件加载时间过长导致。firebug那个uslow的插件也不错。优化方法我就不说了,这个要写的话可以写几本书了。
      

  6.   

    多半都出现在数据库的查询语句上!建议对数据库端做下监控!看看是什么语句比较耗资源,然后针对性的优化sql
      

  7.   

    多谢各位,尤其是ShadowSniper的脚本
    我亲自跑去把服务器重装了
    发现装的是 windows2003
    我换成linux系统后, 网站变得飞快