架構師訓練營 week7 總結
7.1 性能测试:系统性能的主要技术指标
Performance testing
subjective view
User’s real feeling
objective view
Performance metrics
Response time
Concurrent
Concurrent = Throughput x Latency
Throughput => system Processing efficiency
Latency => The length of time the user feels
Throughput
TPS
HPS
QPS
Throughput vs Latency
In short, the throughput is a function of how many stages are in parallel while latency is a function of how many are in series when there are multiple stages in the processing. The stage with the lowest throughput determines the overall throughput.
Different names for different concurrent level testing
Performance testing
Load testing
Add more concurrent requests
Stress testing
More concurrent requests until system crashes
Stability testing
7.2 全链路压测的挑战
Whole business stress testing
Stress testing on all related business services to simulate real users’ behaviors
How to generate mass testing data
How to simulate without any effect on the production environment
Data isolation
Logical isolation
Put testing data and real data together
Might affect production data
Virtual isolation
Use mock testing, do not write testing data to the production environment
Mock data might not be correct
Physical isolation
Real write testing data to other places
7.3 性能优化:系统性能优化的分层思想
You can't optimize the software which doesn’t have any testing
You can’t optimize the software which you don’t really know
Response time: time of finishing the task
Concurrent: Number of tasks processed simultaneously
Throughput: Number of tasks completed per unit time
Performance matrix: System load, Process, Thread, CPU, Memory, Disk, network usage
General methods
Get performance data
Analyze performance data
Analyze architecture and code to find bottleneck
Optimize architecture and code
Performance testing again
Optimization layers
Network
Server/hardware
OS
Virtual system
Fundamental component (Nginx, Jboss….)
Software architecture
cache
async
Cluster
Software code
Concurrent processing
Multi-thread and lock
Resource reusing
Thread pool and object pool
Async processing
Producer and consumer
Data structure
7.4 操作系统:计算机如何处理成百上千的并发请求?
Process/ Thread/ Cpu Core
Process/Thread status
Processing
Ready
Wait
7.5 锁:锁原语 CAS 与各类锁
CAS(Compare and swap)
E,V,N
E => original object’s value
V => value after updating the original object
N => check original object’s value again before an update
Get E => want to update to V => compare E and N again
If E == N => update to V
If E != N => failed, back to get E again
Locking
Biased Lock
Lightweight Lock
Other threads will use spinlock
Heavyweight Lock
Affect performance, others need to wait
總線鎖
Use CPU lock signal
Cache lock
FairSync - lock
NonFairSync - lock
可重入鎖
ReentrantLock (獨享)
Only one thread can the lock at the same time
Shared lock
Write lock
Pessimistic lock
Think all operations are for update => so lock everything
Optimistic lock
Think all operation are not for update => default unlock => but if it finds some object changed when it wants to update=> then give up that update
分段鎖
自旋鎖
评论