当前位置:网站首页>About optimizing API interface response speed

About optimizing API interface response speed

2022-06-10 23:56:00 Li_ XiaoJin

About optimization API Interface response speed ...

Today is just a rough sketch , There are many aspects of this optimization design , Then we will study it carefully .

Today, I found that the interface response is very slow , When the developer tool was called out to check, it was found that the interface actually took time 2 About seconds , Then I checked the background logic , I found a lot of logic , There are several external interfaces called , Also query the database .

Both interfaces are time consuming 1.5 The second . The following is the interface for querying workflow , It seems that we can only find the platform department for optimization .

The rest is to optimize the query efficiency of our system .

First of all, we need to analyze why it is slow

  1. Is it a bottleneck at the resource level ?
  2. Is the cache not added , If you add , Is the load imbalance caused by hot data ?
  3. Does it depend on third-party interfaces ?
  4. Does the interface involve too many businesses , Cause the program to run for a long time ?
  5. Is it right? sql The waiting time is lengthened due to the problems at different levels , Which slows down the interface ?
  6. Network level reasons ? bandwidth ?DNS analysis ?
  7. The code doesn't work ?
  8. Unknown ?

An antidote against the disease

  1. Resources are tight , With the machine , Go ahead , Load balancing !
  2. The problems that caching can solve are not big problems , There are hot spot data, which can be processed by a special machine , Don't let the part affect the whole ( This time it doesn't seem to involve this )
  3. On the one hand, communicate with the third party about interface response problems , On the other hand, pay attention to control the timeout , If non core businesses can be asynchronized for a long time .
  4. Asynchronous operation of non core business . Remember if the code level is non core business , But it will affect user perception , You need to decide carefully whether to be asynchronous .
  5. If the code is bad and the lock is locked , Try to optimize the index or sql sentence , Keep the lock level to a minimum ( Go to line ), Generally speaking, it's almost time to go . If it is a single sql It's slow , It is necessary to analyze whether the index is not added or sql The selected index is wrong , The index should be added , The force index Also added .
  6. Network reasons , You need to find the operation and maintenance personnel , It is difficult to optimize unilaterally .
  7. The code is really bad , There is no cure . Destroy it !

At first, I thought that the machine performance was poor , Look at the system load , It is found that the occupancy rate is not high , It doesn't seem to be a performance problem .

Then I thought it was application optimization , But look at JVM Relevant parameters and Java Usage of the heap , The discovery is not high , I think it should be the database , When the table was created, no relevant index was created .

Then consider adding an index .

Added a composite index , There is also a single column index .

Add the time record in the code before adding , I feel improved .

The rest is the time-consuming external interface .

Copyright: use Creative Commons signature 4.0 International license agreement to license Links:https://lixj.fun/archives/ Optimize api Interface response speed

原网站

版权声明
本文为[Li_ XiaoJin]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/161/202206102238037852.html