今天我把Workerman移动到windows服务器了,开始运行正常,但1个小时候在cmd中报了如下错误:
next called after client was closed - ignoring socket
next called after client was closed - ignoring socket
next called after client was closed - ignoring socket
next called after client was closed - ignoring socket
next called after client was closed - ignoring socket
next called after client was closed - ignoring socket
next called after client was closed - ignoring socket
next called after client was closed - ignoring socket
next called after client was closed - ignoring socket
next called after client was closed - ignoring socket
.......
服务器是centos的。我用php启动的workerman进程,发现该php进程CPU占用97%到100%。
请问该如何优化下?
这个是PHPSocket.IO,不是直接用的workerman。
cpu占用多少和业务模型以及代码质量有关系。
业务模型:比如300个人在线,每个人1秒向其它300人广播消息,那么每秒就是300*300=9W/秒的消息量,cpu占用肯定会很高。
代码质量:还要检查业务逻辑代码是否有问题,比如死循环、疯狂循环超大数组等导致cpu很高。
计算用户访问量
你需要计算下用户访问量,看看PHPPSocket.IO每秒接收消息 发送消息量有多少?是否可以在业务上优化下减少消息量。300人在线导致cpu97%到100%确实有点夸张,不是业务模型有问题就是代码质量问题。
对比
http://www.workerman.net页面底部 用户在线数实时统计功能就是PHPSocket.IO做的,每秒广播给所有在线用户当前在线人数以及打开页面数,每天下午峰值也是300左右,但是因为业务模型简单,能够计算到消息量 300/每秒 左右,所以能看到服务器负载是0,cpu消耗几乎也是0
建议
另外PHPSocket.IO是单进程的,内部工作机制比较复杂,性能相比workerman或者GatewayWorker差很多,建议聊天服务用GatewayWorker去做,可以多进程多服务器部署,支持上万人很轻松。
谢谢了。我抽空把程序改成Gatewayworker版的。
请问目前在php.ini方面有什么优化建议吗?
php.ini没有什么好优化的
我的网站类似于即时留言板,用户提问后不在前台显示,后台管理员回复后,自动在前台显示信息。这个功能用GatewayWorker合适吗?
@1133:还有就是,如果现在改成GatewayWorker,前台js部分不用改变吧?只改变php程序即可?
js要改。你最好确认下到底是什么问题再动手
目前问题就是,workerman占满了CPU,导致很多时候连接失败。但是小弟是菜鸟,实在想不出什么解决办法~
workerman 只是一个运行 app 的容器,你应该在你的应用里面设置记录运行的调试代码,不断定位直到找到什么地方最耗时。
比如
$code_xxx_start = microtime(true);
file_put_contents('/tmp/app_run.log', 'code:xxx:start'.$code_xxx_start."\n", FILE_APPEND)
// codes
file_put_contents('/tmp/app_run.log', 'code:xxx:end'.microtime(true)-$code_xxx_start."\n", FILE_APPEND)
从你的应用的入口代码开始,一步一步不断缩小范围。
@1 了解了。您说的方法我试试。
今天我把Workerman移动到windows服务器了,开始运行正常,但1个小时候在cmd中报了如下错误:
next called after client was closed - ignoring socket
next called after client was closed - ignoring socket
next called after client was closed - ignoring socket
next called after client was closed - ignoring socket
next called after client was closed - ignoring socket
next called after client was closed - ignoring socket
next called after client was closed - ignoring socket
next called after client was closed - ignoring socket
next called after client was closed - ignoring socket
next called after client was closed - ignoring socket
.......
这个错误非常多。
请问这是哪里的问题?
官网说win系统只用做开发调试啊,不建议用在生产环境
@1459:了解了,谢谢啦!