Professional Documents
Culture Documents
CSE451
Andrew Whitaker
This Class
Threads
So,
Our
goals:
Understand
the debate
Analyze arguments
Form our own opinion
2001:
2003:
Background
Problem:
How do scale up
servers to handle many
simultaneous requests
Server
HTTP processing
Send HTTP request
over network
Read and parse
HTTP request
Read file from
disk
Invoke write syscall
time
Send response over
network
Quick Example
Q:
A:
1000
Assuming
These are
blocking calls
Select
Reads,
frameworks (like
Swing)
Single
event-handling
thread
User programs install
event listeners to receive
callbacks
Event
Loop
Event Handlers
Why Events?
A potentially
No
Less
A
memory footprint
More
scalable?
Cut to Ousterhout
Critiquing Ousterhout
Events
We
But,
Programming
Reading
request
In
Reading
File
Writing
File
Stack ripping
while (true) {
// Ask the OS for Sockets with active I/O;
// this blocks if no socket is active
Socket sock = getActiveSocket();
if (sock.isReadable())
handleReadEvent(sock);
if (sock.isWriteable())
handleWriteEvent(sock);
}
Apache
is multi-threaded / multi-process
Lighttpd is event-driven
Which
is better? Why?
Support
The
Thread
Event
Event
of concurrency model is
made for historical reasons
Unfortunately, changing concurrency
models is very difficult
Use
threads
Begin
project
Use
events