doutao5499 2012-09-19 03:01
浏览 71
已采纳

Web服务器速度极慢,而CPU为0-5%,RAM为500/1024 [关闭]

I programmed a web chat, which displayed new entries by refreshing a via an ajax command. This command launched a php file which then created the chat log showing the latest 25 entries. Ajax refreshed this every second for every user.

Then, when there were around 10 users online, the whole website went unbelievably slow and kind of crashed. I figured, that the slowness came from the php script refreshing so often (>10 times every second).

I took a look at my vserver, launched htop to view the processes. The CPU was barely used. It was between 0% and peaked up to 5%. RAM was only half used, at around 500 MB of 1GB (which is standard, even before the chat went online).

I resolved the issue by creating a cron job that creates only 1 html cache-site of the chat log and giving that one out to the users.

But still, I wonder why would the server go so slow, even though CPU and RAM weren't busy at all?

  • 写回答

1条回答 默认 最新

  • dotws86260 2012-09-19 06:12
    关注

    If you aren't maxing out cpu then it's blocking on some other resource. Some possible candidates:

    • is there a db query for every request? If so, how long are they taking?

    • how many threads do you have available to serve requests? How long does each request take? If there is only one thread serving requests then an incoming load of 100 requests per second (which it sounds like you were doing) would start backing up once a request took longer than 10ms, at best.

    As a general strategy, I'd add timers and try to bisect the problem. Take the time at the beginning and end of the request, if this is small then you know the delay is elsewhere.

    Also, for this kind of workload you should consider pushing updates rather than polling. That way you can push a single message to update listening clients and they don't have to poll frequently to get new messages right away.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何用stata画出文献中常见的安慰剂检验图
  • ¥15 c语言链表结构体数据插入
  • ¥40 使用MATLAB解答线性代数问题
  • ¥15 COCOS的问题COCOS的问题
  • ¥15 FPGA-SRIO初始化失败
  • ¥15 MapReduce实现倒排索引失败
  • ¥15 ZABBIX6.0L连接数据库报错,如何解决?(操作系统-centos)
  • ¥15 找一位技术过硬的游戏pj程序员
  • ¥15 matlab生成电测深三层曲线模型代码
  • ¥50 随机森林与房贷信用风险模型