A data type error cause performance problems caused by the failure index

BACKGROUND: An interface is slow, relatively simple logic.

SQL shots are as follows, involving a insert, two and a select update, because the index is there, initially suspected to be caused by performance issues update, there may be a lock.

Project is a PHP project, it is very easy to change the code, so you can print directly timestamp. Said here the next time stamp printing method, my main function is to print, print out a total time, and this time if jmeter almost time, then re-refined stamp print specific methods. as follows:

Print at the start of the method body:

At the end of the method body print:

Both print out time of total time is the total time of the whole process, said here about because of insufficient charge of the project development experience, do not know how the time stamp printed in the Journal, and I do not understand PHP, so I the direct use of echo to print the results returned inside, this does not affect the test results, just print the log which facilitate the statistics.

Now with jmeter pressure measured at look at the results:

 

 

Total time there is more than one second, proved to be problematic in vivo method, continue to print a timestamp more detail.

Although there are more than a hundred lines of code, but this is the main body of four lines, mainly some other data processing, judgment.

After the addition the continued pressure measurement to see the results:

You can clearly see in the select time inside the whole time. See here, just the combination of SQL directly know why, I explained in detail below.

These are two SQL log printing, a close look at the difference, the difference between the quotation marks, without the quotes default int type, but in fact this field is varchar type. Int types of conditions are able to get to the index, which is common sense. Find the reasons to change the codes, quotation marks, type the string becomes as follows:

And then look under the pressure test.

The problem is not just the total time soon, but there is still time jmeter of a few hundred milliseconds, but this result can prove that at least code level has been no problem, if it continues to optimize from the framework layer, nginx, log printing, network, etc. the time before and after the interface calls, not enough experience shows, ThinkPHP poor performance framework, develop leaders and a dinner yesterday I said that before the optimization of how not work, change the ThinkPHP7, many performance problems we can stop the frame As for the choice of what development framework is not able to test our decision, we are only responsible to optimize the best is enough.

找到这个问题后,就直接和开发说改下代码,并说明原因,开发欣然接受并表示感谢。像这种问题,其实是很小的问题,但是带着问题上线后,后果也是很严重的,可以对比下上面的压测结果,这种问题交给我们性能测试组解决,可能半小时内就能定位到问题所在,但是如果我们只告诉开发这个接口慢,让他去优化,这个时间可就不好估计了,有经验的可能一眼找到问题所在,经验不足的可能会耗费很长时间,或者这也就是性能测试的价值所在。

 

作者:幻天行 出处:https://www.cnblogs.com/huantianxing/  本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接。

Guess you like

Origin www.cnblogs.com/1737623253zhang/p/11576493.html