搭建一个WEB服务器,SQL装的2008,系统也是2008版
每天一到下午,访问网站动态页面就相当的慢
没有经过任何处理,第二天早上又快了下面是我监测是一些情况,但是没有头绪怎么查出到底是什么原因所导致,还希望高手能帮忙解决
数据库web服务

解决方案 »

  1.   

    跟踪一下SQL语句,看看谁的速度慢。
      

  2.   

    你把IIS也放到SQLServer上?数据库服务器最好只有SQLServer,不然其他会占掉本来给SQLServer的资源。
      

  3.   

    我的里面只有  自定义报表,没您所说的 性能
    不过我用SQL Server Profiler 跟踪了一下
    发现很多语句暂用了100%,有的语句甚至占用了800%的CPU
    是不是就是这些语句影响了?
      

  4.   

    那就只能优化SQLServer的查询的,先通过3楼的方式找到前几位的查询,然后看看执行计划哪些步骤占了最大的百分比
      

  5.   

    有哪些业务耗用的资源多,排查占用资源大的sql
      

  6.   

    800%?估计你看错地方了。如果我3楼的截图你看不到东西,可能是权限不够。那我给点脚本你用用:
    /* 
    开销较大的查询 
    */ 
    SELECT  ss.SUM_execution_count , 
            t.text , 
            ss.SUM_total_elapsed_time , 
            ss.sum_total_worker_time , 
            ss.sum_total_logical_reads , 
            ss.sum_total_logical_writes 
    FROM    ( SELECT    S.plan_handle , 
                        SUM(s.execution_count) SUM_Execution_count , 
                        SUM(s.total_elapsed_time) SUM_total_elapsed_time , 
                        SUM(s.total_worker_time) SUM_total_worker_time , 
                        SUM(s.total_logical_reads) SUM_total_logical_reads , 
                        SUM(s.total_logical_writes) SUM_total_logical_writes 
              FROM      sys.dm_exec_query_stats s 
              GROUP BY  S.plan_handle 
            ) AS ss 
            CROSS APPLY sys.dm_exec_sql_text(ss.plan_handle) t 
    ORDER BY sum_total_logical_reads DESC
      

  7.   

    根据楼上的语句测试是不是说明SQL语句有很大的问题
      

  8.   

    看下sql 日志。我曾遇到类似的问题,最后发现是日志文件每次自动增长的百分比设置太高,当日志文件太大的时候,按照大的百分比自动扩展,耗时,耗资源。
      

  9.   

    USE [你的库]
    go
    SELECT name,growth FROM sys.database_files 
      

  10.   

    你把这个select语句写出来吧,应该可以优化。
      

  11.   


    Select ID,Off_Name,Off_City,Off_Shop,Off_IsLock,Off_IsDel,Off_HouseType from [FC_Office] o 
    where Off_Shop='城西*紫金' and Off_IsLock=1 and Off_IsDel=0 AND Off_City='杭州' 
    and Off_HouseType <> '100713160720' 
      

  12.   

    键查找主要是因为还缺失索引。检查一下select 中的列是否有索引?包括聚集和非聚集,还有把语句贴出来
      

  13.   

    语句没啥好改的,那你的索引情况呢?fc_office这个表SELECT  ID ,
            Off_Name ,
            Off_City ,
            Off_Shop ,
            Off_IsLock ,
            Off_IsDel ,
            Off_HouseType
    FROM    [FC_Office] o
    WHERE   Off_Shop = '城西*紫金'
            AND Off_IsLock = 1
            AND Off_IsDel = 0
            AND Off_City = '杭州'
            AND (Off_HouseType < '100713160720'  OR Off_HouseType > '100713160720')
      

  14.   

    呵呵,关于这个不等于运算,建立Index是没有用的。我之前发过一个帖子就是关于不等于运算的,你可以参考一下。
    这里是链接:
    http://bbs.csdn.net/topics/390119197
      

  15.   


    Select ID,
           Off_Name,
           Off_City 
    from [FC_Office] o 
    where Off_Shop='城西*紫金' 
          and Off_IsLock=1 
          and Off_IsDel=0 
          AND Off_City='杭州' 
          and Off_HouseType <> '100713160720' 
          order by case ((
          select count(1) from fc_ohouse oo 
          left join [fc_users] u on u.users_id=oo.users_id 
          where sellh_islock=1 
                and sellh_isagent=0 
                And u.users_power > 1 
                and users_lock = 1 
                and users_isdel = 0 
                And oo.office_Id=o.id
                )+(
           select count(1) from fc_shouse_contact sc 
           left join [FC_users] uu on uu.users_id=sc.users_id 
           left join [FC_Shouse] fs on fs.shoph_id=sc.shoph_id 
           where shoph_islock=1 
                 and shoph_isagent=0 
                 And uu.users_power > 1 
                 and users_lock = 1 
                 and users_isdel = 0 
                 And sc.off_Id=o.id)) 
           when 0 then 1 else 0 end, 
           case ((
           select count(1) from fc_ohouse oo 
           left join [fc_users] u on u.users_id=oo.users_id 
           where sellh_islock=1 
                 and sellh_isagent=1 
                 and SellH_InforNum>0 
                 And u.users_power > 1 
                 and users_lock = 1 
                 and users_isdel = 0 
                 And oo.office_Id=o.id
                 )+(
           select count(1) from fc_shouse_contact sc 
           left join [FC_users] uu on uu.users_id=sc.users_id 
           left join [FC_Shouse] fs on fs.shoph_id=sc.shoph_id 
           where shoph_islock=1 
                 and shophc_islock=1 
                 and shoph_isagent=1 
                 And uu.users_power > 1 
                 and users_lock = 1 
                 and users_isdel = 0 
                 And sc.off_Id=o.id))
           when 0 then 1 else 0 end,Off_PublishTime desc,Off_AddTime desc这个是完整的这段的SQL语句
      

  16.   

    你这order by也太!!!!!!!
      

  17.   

    order by那么复杂的话其实就是把结果集整个反来复去,开销不小,不过从执行计划来看应该问题不大。
      

  18.   


    那就神奇了,我通过 SQL Server Profiler 建立跟踪
    CUP占用高的其中之一就是这个,达到218
    类型是:RPC:Completed
    语句是:declare @p1 int
    set @p1=1
    declare @p6 real
    set @p6=5
    declare @p7 real
    set @p7=146
    exec sp_prepexecrpc @p1 output,N'dbo.pager',N'Select ID,Off_Name,Off_City from [FC_Office] o where Off_Shop=''武林*朝晖'' and Off_IsLock=1 and Off_IsDel=0 AND Off_City=''杭州'' and Off_HouseType <> ''100713160720'' order by case ((select count(1) from fc_ohouse oo left join [fc_users] u on u.users_id=oo.users_id where sellh_islock=1 and sellh_isagent=0 And u.users_power > 1 and users_lock = 1 and users_isdel = 0 And oo.office_Id=o.id)+(select count(1) from fc_shouse_contact sc left join [FC_users] uu on uu.users_id=sc.users_id left join [FC_Shouse] fs on fs.shoph_id=sc.shoph_id where shoph_islock=1 and shoph_isagent=0 And uu.users_power > 1 and users_lock = 1 and users_isdel = 0 And sc.off_Id=o.id)) when 0 then 1 else 0 end, case ((select count(1) from fc_ohouse oo left join [fc_users] u on u.users_id=oo.users_id where sellh_islock=1 and sellh_isagent=1 and SellH_InforNum>0 And u.users_power > 1 and users_lock = 1 and users_isdel = 0 And oo.office_Id=o.id)+(select count(1) from fc_shouse_contact sc left join [FC_users] uu on uu.users_id=sc.users_id left join [FC_Shouse] fs on fs.shoph_id=sc.shoph_id where shoph_islock=1 and shophc_islock=1 and shoph_isagent=1 And uu.users_power > 1 and users_lock = 1 and users_isdel = 0 And sc.off_Id=o.id)) when 0 then 1 else 0 end,Off_PublishTime desc,Off_AddTime desc',1,35,@p6 output,@p7 output
    select @p1, @p6, @p7
      

  19.   

    你要做对比,开Profiler跟踪两个窗口,一个是完全没改动前的,收集IO和CPU,然后改过后再收集,看看有没有比较大的提升
      

  20.   

    索引我怀疑是这条SQL语句执行问题
      

  21.   

    好的,只能再观察下
    最大的可能还是SQL有问题
    经过测试,如果页面的SQL语句比较简单,数据少的就很快,就是列表页面慢
      

  22.   

    除了优化sql之外,还有合理利用页面缓存,减少不必要的数据库连接操作等
      

  23.   

    不一定是sql语句的问题,楼主应该从日志大小,是否有死锁等方面去考虑,另外看下windows的日志,也可能有帮助。
      

  24.   

    我来点建议
    1.楼主看下用户连接数是多少
    2.在3楼的图例里,找到“性能-按总CPU排在前面的查询”,看下到底哪些语句消耗了CPU。
    3.10楼已经提供了i/o的分析,试试减少靠前语句返回的行数,在表名后加上 with(nolok)
      

  25.   

    SQL Server自带语句优化的程序,主要是测试需要增加哪些索引。可以将复杂的SQL语句放到里面跑跑看,看看提示需要增加什么索引。