ShannonAI / service-streamer

Boosting your Web Services of Deep Learning Applications.
Apache License 2.0
1.22k stars 187 forks source link

python多线程问题again~ #52

Closed hxyshare closed 4 years ago

hxyshare commented 4 years ago

我又分析了下线程的时间,不是因为线程切换的开销,是由于异步的方式,执行完run_once之后,collect_result线程并没有立刻执行,还是在执行run_forever(),然后执行self.finish_event.set()方法也没有立刻唤醒finished = self._finish_event.wait(timeout),还是在执行run_forever()线程,造成了返回结果的延时会比较高. 请问有什么解决方法吗?要修改为同步的线程模型吗?

hxyshare commented 4 years ago

或者说是,因为python是伪多线程,才导致这个问题的~

Meteorix commented 4 years ago

有个timeout参数和max_latency,可以调一下

hxyshare commented 4 years ago

嗯嗯,感谢回答,我调那个参数,现在我遇到的问题是在QPS比较小的情况下,在run_forever线程里面如果进入time.sleep(TIME_SLEEP)了,collect_result线程不会抢占cpu,还是由run_forever继续执行,会反复进入sleep中.直到某个不确定的时间点才会由collect_result线程执行. 我想问下为什么会出现这种情况.

hxyshare commented 4 years ago

我找到问题的了,在QPS比较低的情况下,因为TIMEOUT = 1时间比较长,output队列会阻塞住,会一直执行run_once,把TIMEOUT = 1设置的小一点就可以了。 感谢~

songyouwei commented 3 years ago

@hxyshare 我也遇到了类似的问题,请问你把TIMEOUT设置成多少了?