当前位置:网站首页>On Web Performance Optimization (1)
On Web Performance Optimization (1)
2022-07-25 21:09:00 【pshdhx_ albert】
Pressure test
Before talking about performance optimization , First, let's talk about stress testing . The project is before the production environment , Pressure test is required first , Simulate concurrency , Look at the throughput of the system , Inform the operation and maintenance personnel of the system throughput bottleneck , Compare with the actual business scenario , Then decide whether to continue to optimize business logic , Upgrade the hardware environment .
Concept
Stress testing examines the current hardware and software systems Maximum load as well as bottleneck Where , It is for the system to be online processing capacity and stability Maintain within a reasonable range , Know what you know .
Wrong type
Memory leak
For example, we write an interface , Create a large number of objects in a loop , No reuse object , When the concurrency comes up , Our objects will be constantly created , So that our memory leaks .
Concurrency and synchronization
When we run with single thread, there is no problem , When our concurrency comes up , There will be all kinds of Thread unsafe The situation of .
Performance index of pressure test
When we run with single thread, there is no problem , When our concurrency comes up , There will be various thread unsafe situations .
Performance index of pressure test
response time (response time: RT)
HPS(hits per Second): Hits per second ;
TPS(transaction per second): Number of transactions processed by the system per second ( Business chain under a complete interface )
QPS(query per second): The number of queries processed by the system per second
Financial industry :1000TPS-50000TPS: Not including Internet activities ,5 ten thousand
The insurance industry :100TPS-100000TPS: Not including Internet activities ,10 ten thousand
Manufacturing industry :10TPS-5000TPS,5K
Internet e-commerce :10000TPS-1000000TPS,100w
Medium sized Internet websites :1000-5wTPS
Small Internet sites :500-1wTPS
Maximum response time : We tested 100w Request , The response time of one request is 90s;
Looking from the outside , Performance testing focuses on the following three indicators
throughput : The number of requests and tasks that the system can process per second (qps and tps)
response time : The time it takes for a service to process a request or a task
Error rate : The proportion of requests with wrong results in a batch of requests
Pressure test tools -JMeter

The throughput of stress test is relatively small , We can adjust JVM Memory
windows Port occupation error and its solution :

influence web The main factors of performance
database
Applications
middleware (tomcat、nginx、gateway gateway )
The Internet IO( The current network speed is slow , Or the server is under pressure , Or the current bandwidth is only 1M--10000 request , Each request 1KB The data of =10MB, It will be affected by bandwidth )
operating system ( Different systems , The kernel is different , Different ways of handling ) Other aspects .
Classification of factors affecting performance
First of all, consider that your application belongs to CPU intensive ( A lot of calculation and sorting ) still IO intensive ( The Internet IO And disk read and write IO);
Watch the surveillance :cpu and io And the occupation of memory and network traffic ;
If it is CPU intensive : Upgrade the server hardware | Increase the number of servers
If it is IO intensive : Replace the SSD + Memory module + Using caching technology + Improve the transmission efficiency of network card , Simply add cpu Can't solve the problem .
Performance monitoring and analysis
java Memory model analysis

Program counter :Program Counter Register
· The record is Being implemented Of Virtual machine bytecode Of Instruction address ;
· This memory area is the only one in JAVA Nothing is specified in the virtual machine specification OutOfMemeoryError Region .
Virtual machine stack :VM Stack
· Describe the JAVA Method Memory model of execution , Each method creates a Stack frame , be used for Store local variable table , The stack of operands , Dynamic links , Method interface Etc .
· The local variable table stores various basic data types known to the compiler , Object reference .
· If the stack depth requested by thread is not enough, it will report StackOverFlowError abnormal .
· If the dynamic expansion capacity of the stack is not enough, it will be reported that OutOfMemeoryError abnormal .
· The virtual machine stack is thread isolated , That is, each thread has its own independent virtual machine stack .
Native Method Stack :Native Stack
The local method stack is similar to the virtual machine stack , It's just that the local method stack uses local methods .
Pile up :Heap
Almost all object instances and arrays allocate memory on the heap ; The heap is the main area managed by the garbage collector , Also known as “GC” Pile up , It's also the place that we consider most about optimization .
About heap memory reclamation process
All object instances and arrays are allocated on the heap . The heap is the main area of the garbage collector , Also known as GC Pile up , It is also where we optimize most .JVM Use C Written language , Can open up space , It's troublesome to free memory . be based on C Repackage , Write an execution engine , Go and translate it java Code .
Heaps can be subdivided into
The new generation
Eden Space : The newly assigned object arrives eden District , First, check whether the memory is enough , What if it's enough , Just allocate memory directly ; If not enough , It's going to take place once GC,( Do it once. young GC, Also called MinorGC, Mainly clean up the Cenozoic space ,eden There is... In it 10 Objects , An object is in use , rest 9 Objects are no longer used , Just put this 9 Kick it out , For this object, we will put it in the survivor area . If minorGC I can't put it down after that , We think this object is a big object , Let's try to put it in the old age --> The old age is when our new generation cannot deal with it . If the old age still can't let go , Then we will have a fullGC, The holocaust , Put the data of all regions of the new generation and the old generation , If it's useless , All kicked out , After kicking out , If you can't put it down , Then an error is reported, and the memory overflows .oom-outofmemory out of memory ) If the survival time of the object in the survivor area exceeds the threshold ( A dozen times of small massacres are still alive ), Just move him to the elderly area .
from suivivor Space 【s0】
to sruvivor Space 【s1】
Old age
Forever / Meta space
java8 The old generation , suffer jvm management ,java8 Later, it will be changed to meta space , Use physical memory directly . therefore , By default , The size of the meta space is limited only by local memory .
utilize java Memory monitoring tools for tuning
jconsole And jvisualvm


jvisualvm Can do
Monitor memory leaks , Tracking garbage collection , Memory at execution time ,cpu analysis , Thread analysis, etc .
State of thread

function : Running ;
Sleep :sleep
wait for :wait
Resident : Idle threads in the thread pool
monitor : Blocked threads , Waiting for lock

Monitor all docker Container of cpu Usage rate docker stats

As can be seen from the figure above ,nginx More wasteful cpu;
JMeter Simulate and analyze concurrent requests


The more middleware , The greater the performance loss , Most of them are lost in the network interaction between middleware .
First, let the throughput of the middleware itself be improved
Improve the transmission efficiency between middleware ( Ethernet cable , network card , Transfer protocol )
Business :
db:MYSQL Optimize
The rendering speed of the template (thymeleaf Cache on ,CPU, Memory )
Nginx Separation of motion and stillness
Summarize the ways to improve performance :
Turn on thymeleaf The cache of ( Close when developing , Turn on when running )
Close the server log ( Not recommended for use )
nginx To separate the movement from the rest
Database indexing
Reduce database interaction ( Request all the data for reuse java To deal with )【 Optimize the business 】
Improve memory ,jvm The new generation is enlarged, etc
Cache
Next :
introduce redis Cache problems and solutions
边栏推荐
- When MySQL imports data, it has been changed to CSV utf8 file and the file name is English. Why does it still fail to import
- How to store pictures in the database "suggested collection"
- Success factors of software R & D effectiveness measurement
- Golang language quickly get started to comprehensive practical notes (go language, beego framework, high concurrency chat room, crawler)
- Niuke-top101-bm37
- Explain in detail the principle of MySQL master-slave replication "suggestions collection"
- 数据库sql语句练习题「建议收藏」
- LeetCode刷题——猜数字大小II#375#Medium
- Introduction to MySQL engine and InnoDB logical storage structure
- Leetcode-146: LRU cache
猜你喜欢

Solution to oom exceptions caused by improper use of multithreading in production environment (supreme Collection Edition)

Advanced technology management - how can the team be broken?

Leetcode-155: minimum stack

leetcode-6129:全 0 子数组的数目

【网络教程】IPtables官方教程--学习笔记2

Cesium 多边形渐变色纹理(Canvas)

leetcode-6125:相等行列对

Success factors of software R & D effectiveness measurement

Matlab---eeglab check EEG signal
![[fiddlertx plug-in] use Fiddler to capture the package Tencent classroom video download (unable to capture the package solution)](/img/de/7a288ee8e6001235d4869c10503932.png)
[fiddlertx plug-in] use Fiddler to capture the package Tencent classroom video download (unable to capture the package solution)
随机推荐
An interview question about interface and implementation in golang
leetcode-6131:不可能得到的最短骰子序列
leetcode-6129:全 0 子数组的数目
Beisen Holdings' IPO: a total loss of 4.115 billion yuan in three years, and a total of 2.84 billion yuan in the previous nine rounds of financing
如何自动生成短链?如何在线批量生成带UTM参数的链接?
[FAQ] access the HMS core push service, and the server sends messages. Cause analysis and solutions of common error codes
Remote—基本原理介绍
npm 模块 移除_【已解决】npm卸载模块后该模块并没有从package.json中去掉[通俗易懂]
Airtest解决“自动装包”过程中需要输入密码的问题(同适用于随机弹框处理)
Fusing and degrading Sentinel
Per capita Swiss number series, Swiss number 4 generation JS reverse analysis
[technical dry goods] how to ensure the idempotency of the interface?
PayPal PHP product trial period "recommended collection"
Brush questions with binary tree (4)
Leetcode-6125: equal row and column pairs
Unity VS—— VS中默认调试为启动而不是附加到Unity调试
Yolov7 training error indexerror: list index out of range
All non isomorphic subgraphs of a directed complete graph of order 3 (number of different hook graphs)
Leetcode-6126: designing a food scoring system
使用oap切面导致controller被重复调用
