[PYTHON] Performance improvement efforts

Last time, I wrote about the tests that my team is doing. This time, I would like to write about the points I am careful about when implementing it, and New Relic and locust used for performance improvement.

Things to be careful about in implementation

The most important thing to watch out for is "If you are selecting or creating in a loop, put it out of the loop". Get it with select in, bulk create, this alone will improve the response quite a bit. The algorithm manages to do that after removing it.

Introducing tools

No matter how careful you are, you are human. There are cases where it is left as it is. If you check the processing time in New Relic, you can see the situation where the same select statement is issued many times. If it is found, we will consider and correct it so that it can be done only once.

New Relic ##

Is there any slow processing?

スクリーンショット 2015-11-02 14.34.57.png

why~?

スクリーンショット 2015-11-02 14.54.57.png

First, look for a place that can be fixed like this and try to improve it.

Locust ## http://locust.io Locust is a load testing tool. After making improvements in New Relic, use locust to load and check the API response. If you do so, the response will be slow while waiting for the lock to be released, or the result will be "* Deadlock occurred! *" In the first place, so "Let's narrow the lock range" or "The lock order was wrong!" It was discovered that it helped to make further improvements. It wasn't often that it was still slow, but in that case it would be better to review the logic.

Why Locust? ### **I do not know! ** ** I wasn't in charge! When I'm writing this item, I feel like I'm trying to pass this item in a hurry.

However, it was easier to understand when compared to JMeter, which I played with when I was about to do a load test before. The reason is that the load test is written in python code. I thought I could write it myself. I have no experience in implementing the load test code, so I will study and post it later, but I will set the number of access for heavy users and light users, set the ratio of hitting the API, and apply the load. I understand (well, I think JMeter can do that too).

So, I would like to talk about Locust next time.

Recommended Posts

Performance improvement efforts
Detailed explanation Monitoring & performance improvement with NewRelic-Part 2
Actix-web performance
Detailed explanation Monitoring & performance improvement with NewRelic-Part 1
Improvement of performance metrix by two-step learning model