简体   繁体   English

在没有可用系统资源的情况下,对Django进行压力测试会使其变慢

[英]Stress test on Django makes it slow while there are free system resources

Today I was doing a stress test to a new Django (1.5.4) running on an Ubuntu Server 12.04 site before going into production and I've found some unexpected results: 今天,在投入生产之前,我对在Ubuntu Server 12.04站点上运行的新Django(1.5.4)进行了压力测试,发现了一些意外的结果:

Doing 50 requests per second, htop showed a CPU usage of ~50% and RAM also ~50%. 每秒执行50个请求,htop显示CPU使用率约为50%,RAM也约为50%。 I'm not currently using Django cache and doing a normal browser request while doing the stress test it took ~30s to load each page (without any load it takes <= 2s). 我目前未使用Django缓存,并且在进行压力测试时没有执行正常的浏览器请求,因此加载每个页面大约需要30秒的时间(没有任何加载,其花费<= 2s)。 The server didn't crash during the test, but I dont understad why if there are almost 50% of the resources free it lasts so much... I expected to see a higher CPU and memory usage! 服务器在测试过程中没有崩溃,但是我没有理解为什么几乎有50%的可用资源会持续这么长时间……我希望看到更高的CPU和内存使用率!

So, my question is: Is there any Django default setting that limits the number of requests per second? 因此,我的问题是:是否有任何Django默认设置会限制每秒的请求数? Or does Apache or mod_wsgi have any kind of limit? 还是Apache或mod_wsgi有任何限制? Do I have to change some MySQL config? 我必须更改一些MySQL配置吗?

(Note: I'm a software engineer, not sysadmin). (注意:我是软件工程师,不是sysadmin)。

Probably caching is your answer. 可能是缓存是您的答案。 I don't know how Django runs on Apache as I run a Gunicorn setup but it makes round trips for every database call. 当我运行Gunicorn设置时,我不知道Django如何在Apache上运行,但是它使每个数据库调用都往返。

If you institute some memcache to handle common result sets you should see a large improvement so you don't have to make trips for each request. 如果您建立一些内存缓存来处理常见的结果集,则应该会看到很大的改进,因此您不必为每个请求而去旅行。

Also, 50 concurrent connection requests at a time seems like a lot. 同样,一次50个并发连接请求似乎很多。 Try to tone it down to 5 or 10 then 25 instead of starting at 50. 尝试将其调低为5或10,然后调为25,而不是从50开始。

Just my opinion. 只是我的观点。

How many workers of django you are running? 您正在运行多少名django工人? Maybe server can't load to 100% because you are running small amount of workers, but there are many database connections, so most of the time workers are waiting database, and blocking new connections. 也许服务器无法加载到100%,因为您正在运行少量工作程序,但是数据库连接很多,因此大多数情况下工作程序正在等待数据库并阻止新连接。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM