Code Development for High Performance Servers Topics n
- Slides: 8
Code Development for High Performance Servers Topics n n Multithreaded Servers Event Driven Servers l Example - Game Server code (Quake) l A parallelization exercise for game server code
Goals Maximize server utilization and decrease its latency. n Server process doesn’t block! Robust under heavy loads. Relatively easy to develop. – 2–
Multi-threaded Servers One thread per request executing the request handler. Each thread is listening on a socket A thread blocking on I/O doesn’t block the server. Request Handler A Ex: Apache, My. Sql. B C – 3– Function Calls
Multi-threaded Servers (Cont. ) Advantages: + Relatively easy to develop. Disadvantages: Poor performance. n n Thread scheduling. Context switching. Doesn’t scale. n – 4– Under heavy load , many threads would be created exhausting kernel’s memory, crashing the server.
Event Driven Servers Single thread (event loop). Event Loop + High performance. + Scalable/Robust. A 1 A 2 - Hard to write B 1 B 2 C 1 C 2 – 5– “Blocking” operation
Background: AIO Asynchronous I/O mainly used for disk reads/writes. Issue disk request and return immediately without blocking for results. On completion an event is raised. – 6–
Event Driven Servers (cont) Single thread (event loop). Hard to write (server can’t block !) Event Loop - AIO operations. - Requests (events) put in Event Queue. A 1 A 2 - Continuations (for requests) B 1 B 2 - When receiving a reply C 1 C 2 – 7– “Blocking” operation
Summary – 8– Multi. Threaded Event Driven Scalable No Yes High Performance No Yes “Easy” to build Yes No >1 thread Yes No Thread / request? Yes No Examples Apache, My. SQL Zeus Web Server