Program optimization
프로그램 최적화(program optimization) 또는 소프트웨어 최적화(software optimization)는 정보 공학에서 시스템을 수정하여 어떠한 면의 작업이 더 효과적으로, 또는 자원을 덜 사용하도록 만드는 작업을 말한다. 이를테면, 컴퓨터 프로그램은 더 빠르게 실행되거나 기억 장치나 자원을 덜 차지하게 하여 운영케 하거나, 전력을 덜 쓰게 함으로써 최적화될 수 있다. 이러한 시스템은 인터넷과 같은 완전한 네트워크나 컴퓨터의 모임으로서 단일의 컴퓨터 프로그램이 될 수 있다.
Performance Tuning
Performance tuning is the improvement of system performance. This is typically a computer application, but the same methods can be applied to economic markets, bureaucracies or other complex systems. The motivation for such activity is called a performance problem, which can be real or anticipated. Most systems will respond to increased load with some degree of decreasing performance. A system's ability to accept higher load is called scalability, and modifying a system to handle a higher load is synonymous to performance tuning.
Systematic tuning follows these steps:
- Assess the problem and establish numeric values that categorize acceptable behavior.
- Measure the performance of the system before modification.
- Identify the part of the system that is critical for improving the performance. This is called the bottleneck.
- Modify that part of the system to remove the bottleneck.
- Measure the performance of the system after modification.
- If the modification makes the performance better, adopt it. If the modification makes the performance worse, put it back the way it was.
This is an instance of the measure-evaluate-improve-learn cycle from quality assurance.
A performance problem may be identified by slow or unresponsive systems. This usually occurs because high system loading, causing some part of the system to reach a limit in its ability to respond. This limit within the system is referred to as a bottleneck.
A handful of techniques are used to improve performance. Among them are code optimization, load balancing, caching strategy, distributed computing and self-tuning.
Compiler
Memory
- Memory pool
- memcpy
- Direct memory access (DMA)
- Duffs device
- Zero-copy
- Paging
- Port-mapped I/O
- Memory-mapped I/O
- Memory-mapped file
- mmap
- OOM killer
- cgroup
Hardware
- PerformanceTuning:DiskIO
- Managing Disk Space - 디스크 용량이 부족할 때 관련 이슈.
- SSD (Hardware)
- SIMD
CPU
- Arithmetic logic unit - CPU 산술 연산에 대한 설명.
- Load
- CPU cache
- NUMA
- Context Switching
동기화 (Synchronization)
- Mutex
- Lock-free
- Compare-And-Swap (CAS)
- Read-Copy-Update (RCU)
- Reader-Writer lock
- Spinlock
- Blocking lock
- File lock
Process/Thread
- Multi-process
- Multi-threaded
- Green threads
- User level scheduling
- Work-stealing queue
- thread pool 설계
- Coroutine
- Async-await
Networking
- PerformanceTuning:NetworkIO
- I/O multiplexing
- DPDK
- XDP
TCP tuning
- Buffer size
- Window size
- Congestion control (혼잡 제어)
- Nagle algorithm (네이글 알고리즘)
Load Balancing
- L4/L7 로드밸런싱
- Consistent hashing
- 분산 시스템
- Connection pooling
- keep-alive
High Performance Browser Networking
- Site: [강추] hpbn.co - High Performance Browser Networking
- Download: Hpbn.co.tar.gz
Performance is a feature. This book provides a hands-on overview of what every web developer needs to know about the various types of networks (WiFi, 3G/4G), transport protocols (UDP, TCP, and TLS), application protocols (HTTP/1.1, HTTP/2), and APIs available in the browser (XHR, WebSocket, WebRTC, and more) to deliver the best—fast, reliable, and resilient—user experience.
- Networking 101
HTTP/Web
- Web cache
- Lighthouse
- Nginx#Performance Tunning - 고성능 Nginx를위한 튜닝
- WebProgramming:PerformanceTunning - 웹 최적화 방법.
- Web development#웹사이트 크기가 14kB 미만이어야 하는 이유
- WebFont:PerformanceTunning - 웹 폰트 최적화.
네트워크 토폴로지 (Network topology)
Filesystem
- Direct I/O vs Buffered I/O
- fsync/fdatasync와 durability 보장
- SSD TRIM
- write amplification
- Format
Programming language
- C++:BitHacks - 비트 연산 팁&트릭
- Python:PerformanceTunning
Database
- RDBMS:ProgramOptimization - RDBMS 최적화.
- PostgreSQL:Performance
- ACID vs BASE 트레이드오프
- Isolation level별 동시성 제어
- Connection pooling과 prepared statements
- Query plan 분석과 인덱스 전략
- Sharding과 replication 설계
확장성 및 아키텍처
수평/수직 확장
- Stateless 서비스 설계 원칙
- Session clustering과 분산 캐시
- Service mesh와 마이크로서비스 패턴
- Event-driven architecture와 메시지 큐
분산 시스템
- CAP theorem과 일관성 모델
- Consensus 알고리즘 (Raft, Paxos)
- Distributed tracing과 observability
- Circuit breaker와 bulkhead 패턴
모니터링 및 성능 최적화
시스템 메트릭
- CPU utilization vs load average 차이
- Context switch rate와 run queue depth
- Memory bandwidth와 saturation
- Disk I/O patterns (sequential vs random)
프로파일링
- Flame graph로 CPU 병목 분석
- Memory profiling (heap, leak detection)
- perf, eBPF 같은 저수준 도구 활용
- Application Performance Monitoring (APM)
성능 튜닝
- Amdahl's law와 병렬화 한계
- Latency percentiles (p50, p95, p99)
- Queueing theory와 Little's law
- Batch processing vs Streaming tradeoffs
보안 및 권한
- Rate limiting과 DDoS 방어
- TLS/SSL 성능 최적화
- JWT vs Session 기반 인증
- Container security와 privilege escalation
- Filesystem in Userspace (FUSE)
안정성
- Graceful shutdown과 zero-downtime deployment
- Health check와 readiness probe 설계
- Chaos engineering 원칙
- Backup과 disaster recovery 전략
See also
Favorite site
- Wikipedia (en) Program optimization
- Wikipedia (en) Performance Tuning에 대한 설명
- 다크 프로그래머 :: 최적화 기법의 직관적 이해
- 컴퓨터 시스템: 프로그램 최적화 (1) (비효율적인 함수 호출, 비효율적인 메모리 참조)
- 컴퓨터 시스템: 프로그램 최적화 (2) (루프 풀기(Loop Unrolling), 재결합 변환(Reassociation Transform), 병렬 누산기(Separate Accumulators))
- 컴퓨터 시스템: 기계어 - 부동소수점
- [추천] Naver D2 - 네이버 메인 페이지의 트래픽 처리 1
- [추천] Software optimization resources (Optimization manuals; c와 asm을 사용한 메모리 복사 등 최적화 코드 포함)
- 성능이 중요한 이유 | Web Fundamentals | Google Developers
- [추천] 서버에 걸리는 부하, 추측하지 말고 계측하자 2
- 실험: 느린 빌드 시간의 숨겨진 비용 | GeekNews
- (원문) Experiment: The hidden costs of waiting on slow build times | The GitHub Blog
- 더 좋은 하드웨어에 비용을 지불하는 것이 실제로 더 저렴하고, 개발자에게 더 좋음(방해요소를 줄임)
- 위 실험의 경우, 빌드시간에 $4~5 를 더 지불하는 것이 1인 개발자에게는 $40, 5명 팀에게는 $200 이상 절약해주면서, 태스크 스위칭에 드는 한시간도 아껴줌
- 물론 대규모 회사에서는 빌드당 $4~5를 쓰는 것은 꽤 커질수도 있지만, 매몰되는 생산성 비용 역시 커짐