当前位置:网站首页>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
边栏推荐
- Leetcode-155: minimum stack
- Using the OAP aspect causes the controller to be called repeatedly
- Sum of two numbers and three numbers
- The international summit osdi included Taobao system papers for the first time, and end cloud collaborative intelligence was recommended by the keynote speech of the conference
- Pychart automatically enters the test mode when running the program
- Leetcode-6131: the shortest dice sequence impossible to get
- kali修改更新源(无法安全的用该源更新)
- Brush questions with binary tree (4)
- Use Navicat to connect to MySQL database through SSH channel (pro test is feasible)
- cv图像翻转,EmguCV图像旋转「建议收藏」
猜你喜欢

Detailed explanation of document operation

Record the transfer of domain names from Alibaba cloud service providers to Huawei cloud

Leetcode-6125: equal row and column pairs

作为测试,如何理解线程同步异步

Unity vs -- the default debugging in VS is to start rather than attach to unity debugging

leetcode-79:单词搜索

Interface testing tool restlet client

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

Force deduction ----- calculate the money of the force deduction bank

leetcode-114:二叉树展开为链表
随机推荐
leetcode-114:二叉树展开为链表
cuda_error_out_of_memory(out of memory怎么办)
IEC61131 address representation
476-82(322、64、2、46、62、114)
浅谈web性能优化(一)
zigbee物联网开发平台(工业物联网)
Unity vs -- the default debugging in VS is to start rather than attach to unity debugging
Solution to oom exceptions caused by improper use of multithreading in production environment (supreme Collection Edition)
leetcode-6126:设计食物评分系统
In June 2021, the interview suffered a Waterloo. Is it so convoluted now
MySQL master-slave replication data synchronization, summary of common problems
Scan delete folder problems
Temperature and humidity environment monitoring system based on stm32
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
图片怎么存储到数据库里「建议收藏」
Introduction to MySQL engine and InnoDB logical storage structure
The role of the resize function is "suggestions collection"
一道golang中defer和函数结合的面试题
Pychart automatically enters the test mode when running the program
The inexplicability of Intel disassembly
