项目使用flask框架,是个较复杂的推荐系统,需要从设定的各类数据源取(有些复杂的排序、过滤)推荐数据,大部分数据存取使用redis,经过常规优化后取数据控制在200ms以内。
为进一步大幅度提升性能采用gevent作为并发框架,但是发现性能反而下降了大概25%,原来一个数据源就30ms,改造后上升到一两百毫秒都有,这是为什么?这种情况大家会怎么进一步调优了。
(使用场景除了比较集中的取数据模块,其他地方还有零星用到gevent)
黄舟2017-04-18 09:36:54
This question is a bit complicated. It is recommended that the subject introduce the environment and startup parameters, the number of running processes, and how to run it.
In the absence of these conditions, I would like to talk about this problem based on my own understanding. The original intention of this question is to use gevent to improve performance, but it is found that the performance is reduced. At this time, it is necessary to examine where the performance is reduced. .
The questioner’s criterion for measuring performance degradation is that it takes longer to obtain data. Here I will share my personal opinion. First of all, the questioner does not know how gevent works. The role of gevent is to run multiple coroutines in one thread. It is suitable for multiple IO operations. If it is mixed with a little more CPU operations, it will be difficult to grasp the time. For example, the question asked here requires tens of milliseconds. What if one of your coroutines runs a CPU of one or two hundred milliseconds? operation, then no matter how fast your other coroutine IO is, it will not help.
Also, it needs to be emphasized that introducing gevent will not speed up the speed of obtaining data. For example, it was originally 30ms. After the introduction, it will not become less, but will only become more. So what are the benefits of introducing it? It turns out that you can receive 33 client requests within 1 second. After the introduction, you may be able to receive 100/s or 300/s. This is the benefit of gevent.
I can only give so many suggestions without fully understanding the subject's environment. If the subject does not understand, you can provide further analysis of the previous information.