CSCI
-
1680
Network Programming II
Rodrigo Fonseca
Today
•
Network programming
–
Programming Paradigms
–
Programming libraries
•
Final project
Low
-
level Sockets
•
Address Family AF_PACKET
–
Socket type: SOCK_RAW
•
See link
-
layer (Ethernet) headers. Can send broadcast
on a LAN. Can get/create non
-
IP packets
–
Socket type: SOCK_DGRAM
•
See IP headers. Can get protocols other than
TCP/UDP: ICMP, SCTP, DCCP, your own…
•
Can cook your own IP packets
–
Must have root privileges to play with these
Building High Performance
Servers
The need for concurrency
•
How to improve throughput?
–
Decrease latency (throughput
α
1/latency)
–
Hard to do!
•
Optimize code (this you should try!)
•
Faster processor (no luck here, recently)
•
Speed of light isn’t changing anytime soon…
•
Disks have to deal with things like inertia!
–
Do multiple things at once
•
Concurrency
–
Allows overlapping of computation and I/O
–
Allows use of multiple cores, machines
High
-
performance Servers
Common Patterns
Read
Request
Find
File
Read File
Send Data
Get
Conn
Read
Request
Find
File
Read File
Send Data
Accept
Conn
Get
Conn
Send
Header
Process 1
Read
Request
Find
File
Read File
Send Data
Get
Conn
Read
Request
Find
File
Read File
Send Data
Accept
Conn
Get
Conn
Send
Header
Process N
Fi
g
u
r
e
2
:
M
u
l
t
i
-
Pr
o
c
e
s
s
-
I
n
t
h
e
M
P
m
o
d
e
l
,
each
s
er
v
er
pr
oc
e
s
s
ha
ndl
e
s
one
r
e
que
s
t
a
t
a
t
i
m
e
.
P
r
oc
e
s
s
e
s
e
x
e
c
ut
e
th
e
p
r
o
c
e
s
s
in
g
s
ta
g
e
s
s
e
q
u
e
n
tia
lly
.
Read
Request
Find
File
Read File
Send Data
Get
Conn
Read
Request
Find
File
Read File
Send Data
Accept
Conn
Get
Conn
Send
Header
Fi
g
u
r
e
3
:
M
u
l
t
i
-
T
h
r
e
a
d
e
d
-
T
h
e
M
T
m
o
d
e
l
u
s
e
s
a
s
i
n
g
l
e
ad
d
r
es
s
s
p
ace
w
i
t
h
m
u
l
t
i
p
l
e
co
n
cu
r
r
en
t
t
h
r
ead
s
o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d
w
i
t
h
t
he
select
ope
ra
t
i
on.
Th
i
s
m
a
k
e
s
i
t
d
i
f
fi
c
u
l
t
o
r
i
m
p
o
s
s
i
b
l
e
t
o
s
i
m
u
l
t
a
n
e
o
u
s
l
y
ch
eck
f
o
r
co
m
p
l
et
i
o
n
o
f
n
et
w
o
r
k
an
d
d
i
s
k
I
/
O
e
v
en
t
s
i
n
an
ef
fi
ci
en
t
m
an
n
er
.
M
o
r
eo
v
er
,
o
p
er
at
i
o
n
s
s
u
ch
as
open
an
d
stat
on
fi
l
e
de
s
c
r
i
pt
or
s
m
a
y
s
t
i
l
l
be
bl
oc
ki
ng.
Fo
r
t
h
e
s
e
r
e
a
s
o
n
s
,
e
x
i
s
t
i
n
g
S
P
E
D
s
e
r
v
e
r
s
d
o
n
o
t
u
s
e
th
e
s
e
s
p
e
c
ia
l
a
s
y
n
c
h
r
o
n
o
u
s
d
is
k
in
te
r
f
aces
.
A
s
a
r
es
u
l
t
,
fil
e
read
ope
r
a
t
i
ons
t
ha
t
do
not
hi
t
i
n
t
he
fi
l
e
c
a
c
he
m
a
y
cau
s
e
t
h
e
m
ai
n
s
er
v
er
t
h
r
ead
t
o
b
l
o
ck
,
cau
s
i
n
g
s
o
me
l
o
s
s
in
c
o
n
c
u
r
r
e
n
c
y
a
n
d
p
e
r
f
o
r
m
a
n
c
e
.
3.
4
A
symme
t
r
ic
M
u
lt
i-
Pr
oc
e
s
s
E
ve
n
t
-
D
r
i
ve
n
Th
e
A
s
y
m
m
e
t
r
i
c
M
u
l
t
i
-
P
r
o
c
e
s
s
Ev
e
n
t
-
D
r
i
v
e
n
(A
M
P
E
D
)
a
rc
h
i
t
e
c
t
u
re
,
i
l
l
u
s
t
ra
t
e
d
i
n
F
i
g
u
re
5
,
c
o
m
b
i
n
e
s
Read
Request
Find
File
Read File
Send Data
Get
Conn
Read
Request
Find
File
Read File
Send Data
Accept
Conn
Get
Conn
Send
Header
Process 1
Read
Request
Find
File
Read File
Send Data
Get
Conn
Read
Request
Find
File
Read File
Send Data
Accept
Conn
Get
Conn
Send
Header
Process N
Fi
g
u
r
e
2
:
M
u
l
t
i
-
Pr
o
c
e
s
s
-
I
n
t
h
e
M
P
m
o
d
e
l
,
each
s
er
v
er
pr
oc
e
s
s
ha
ndl
e
s
one
r
e
que
s
t
a
t
a
t
i
m
e
.
P
r
oc
e
s
s
e
s
e
x
e
c
ut
e
th
e
p
r
o
c
e
s
s
in
g
s
ta
g
e
s
s
e
q
u
e
n
tia
lly
.
Read
Request
Find
File
Read File
Send Data
Get
Conn
Read
Request
Find
File
Read File
Send Data
Accept
Conn
Get
Conn
Send
Header
Fi
g
u
r
e
3
:
M
u
l
t
i
-
T
h
r
e
a
d
e
d
-
T
h
e
M
T
m
o
d
e
l
u
s
e
s
a
s
i
n
g
l
e
ad
d
r
es
s
s
p
ace
w
i
t
h
m
u
l
t
i
p
l
e
co
n
cu
r
r
en
t
t
h
r
ead
s
o
f
e
x
ecu
-
tio
n
.
E
a
c
h
th
r
e
a
d
h
a
n
d
le
s
a
r
e
q
u
e
s
t.
Si
n
c
e
e
a
c
h
p
r
o
c
e
s
s
h
a
s
i
t
s
o
w
n
p
r
i
v
a
t
e
a
d
d
r
e
s
s
s
p
a
c
e
,
no
s
ync
hroni
z
a
t
i
on
i
s
ne
c
e
s
s
a
ry
t
o
ha
ndl
e
t
he
proc
e
s
s
i
ng
of
di
f
f
e
r
e
nt
H
T
T
P
re
que
s
t
s
2
.H
o
w
e
v
e
r
,
i
t
m
a
y
b
e
m
o
r
e
di
f
fi
c
ul
t
t
o
pe
r
f
or
m
opt
i
m
i
z
a
t
i
ons
i
n
t
hi
s
a
r
c
hi
t
e
c
t
ur
e
t
ha
t
re
l
y
o
n
g
l
o
b
a
l
i
n
fo
rm
a
t
i
o
n
,
s
u
c
h
a
s
a
s
h
a
re
d
c
a
c
h
e
o
f
va
l
i
d
U
R
L
s
.
F
i
g
u
r
e
2
i
l
l
u
s
t
r
a
t
e
s
t
h
e
M
P
a
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u
s
in
g
o
n
ly
s
u
p
p
o
r
t
th
a
t
is
w
id
e
ly
a
v
a
ila
b
le
in
m
o
d
e
r
n
ope
ra
t
i
ng
s
ys
t
e
m
s
.
In
a
U
N
I
X
s
ys
t
e
m
,
A
M
P
E
D
us
e
s
t
he
s
t
a
nda
rd
non-
bl
oc
ki
ng
read
,
write
,a
n
d
accept
sy
st
e
m
c
a
l
l
s
o
n
so
c
k
e
t
s
a
n
d
p
i
p
e
s,
a
n
d
t
h
e
select
sy
st
e
m
c
a
l
l
t
o
t
e
st
f
o
r
I/
O
c
om
pl
e
t
i
on.
T
he
mmap
ope
r
a
t
i
on
i
s
us
e
d
t
o
a
c
c
e
s
s
da
t
a
from
t
he
fi
l
e
s
ys
t
e
m
a
nd
t
he
mincore
ope
ra
t
i
on
i
s
us
e
d
t
o
c
he
c
k
i
f
a
fi
l
e
i
s
i
n
m
a
i
n
m
e
m
or
y
.
No
t
e
t
h
a
t
t
h
e
h
e
l
p
e
r
s
c
a
n
b
e
i
m
p
l
e
m
e
n
t
e
d
e
i
t
h
e
r
a
s
ke
r
ne
l
t
hr
e
a
ds
w
i
t
hi
n
t
he
m
a
i
n
s
e
r
v
e
r
pr
oc
e
s
s
or
a
s
s
e
p-
ar
at
e
p
r
o
ces
s
es
.
Ev
en
w
h
en
h
el
p
er
s
ar
e
i
m
p
l
emen
t
ed
as
se
p
a
r
a
t
e
p
r
o
c
e
sse
s,
t
h
e
u
se
o
f
mmap
al
l
o
w
s
t
h
e
h
el
p
er
s
to
initia
te
the
r
e
a
d
ing
o
f
a
fi
l
e
from
d
is
k
w
ithout
intro-
duc
i
ng
a
ddi
t
i
ona
l
da
t
a
c
opyi
ng.
In
t
hi
s
c
a
s
e
,
bot
h
t
he
mai
n
s
er
v
er
p
r
o
ces
s
an
d
t
h
e
h
el
p
er
mmap
a r
e
q
u
e
s
t
e
d
fi
l
e
.
Th
e
h
e
l
p
e
r
t
o
u
c
h
e
s
a
l
l
t
h
e
p
a
g
e
s
i
n
i
t
s
m
e
m
o
r
y
m
a
p
p
i
n
g
.
On
c
e
fi
n
i
s
h
e
d
,
i
t
n
o
t
i
fi
e
s
t
h
e
m
a
i
n
s
e
r
v
e
r
p
r
o
c
e
s
s
t
h
a
t
i
t
i
s
no
w
s
a
f
e
t
o
t
ra
ns
m
i
t
t
he
fi
l
e
w
i
t
hout
t
he
r
i
s
k
of
bl
oc
ki
ng.
4
D
e
s
i
gn
c
o
m
p
ar
i
s
o
n
In
t
h
i
s
s
e
c
t
i
o
n
,
w
e
p
re
s
e
n
t
a
q
u
a
l
i
t
a
t
i
v
e
c
o
m
p
a
ri
s
o
n
of
t
he
pe
r
f
or
m
a
nc
e
c
ha
r
a
c
t
e
r
i
s
t
i
c
s
a
nd
pos
s
i
bl
e
opt
i
m
i
z
a
-
tio
n
s
in
th
e
v
a
r
io
u
s
W
e
b
s
e
r
v
e
r
a
r
c
h
ite
c
tu
r
e
s
p
r
e
s
e
n
te
d
in
th
e
p
r
e
v
io
u
s
s
e
c
tio
n
.
Event Dispatcher
Read
Request
Read
Request
Find
File
Find
File
Get
Conn
Accept
Conn
Send Header
Read File
Send Data
Read File
Send Data
Send Header
Helper 1
Helper 2
Helper k
Fi
g
u
r
e
5
:
A
s
y
m
m
e
t
r
i
c
M
u
l
t
i
-
Pr
o
c
e
s
s
E
v
e
n
t
D
r
i
v
e
n
-
T
h
e
AM
P
E
D
m
o
d
e
l
u
s
e
s
a
s
i
n
g
l
e
p
r
o
c
e
s
s
f
o
r
e
v
e
n
t
-
d
r
i
v
e
n
r
e
-
que
s
t
proc
e
s
s
i
ng,
b
ut
ha
s
ot
he
r
he
l
pe
r
proc
e
s
s
e
s
t
o
ha
n-
dl
e
s
om
e
di
s
k
ope
ra
t
i
ons
.
4
.
1
P
e
r
f
o
r
ma
n
c
e
c
h
a
r
a
c
t
e
r
i
s
t
i
c
s
Di
s
k
o
p
e
r
a
t
i
o
n
s
- T
h
e
c
o
s
t
o
f h
a
n
d
l
i
n
g
d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H
T
T
P
r
eq
u
es
t
,
w
h
i
ch
h
as
su
b
st
a
n
t
i
a
l
m
e
m
o
r
y
a
n
d
k
e
r
n
e
l
o
v
e
r
h
e
a
d
s.
Di
s
k
u
t
i
l
i
z
a
t
i
o
n
- T
h
e
n
u
m
b
e
r o
f
c
o
n
c
u
r
r
e
n
t
d
i
s
k
r
e
-
que
s
t
s
t
ha
t
a
s
e
r
v
e
r
c
a
n
ge
ne
r
a
t
e
a
f
f
e
c
t
s
w
he
t
he
r
i
t
c
a
n
be
ne
fi
t
f
r
om
m
ul
t
i
pl
e
di
s
ks
a
nd
di
s
k
he
a
d
s
c
he
dul
i
ng.
Th
e
M
P
/
M
T
m
o
d
e
l
s
c
a
n
c
a
u
s
e
o
n
e
d
i
s
k
r
e
q
u
e
s
t
p
e
r
p
r
o
-
ces
s
/
t
h
r
ead
,
w
h
i
l
e
t
h
e
A
M
P
E
D
m
o
d
el
can
g
en
er
at
e
o
n
e
re
que
s
t
pe
r
he
l
pe
r
.
In
c
ont
ra
s
t
,
s
i
nc
e
a
l
l
us
e
r
-
l
e
v
e
l
pro-
ces
s
i
n
g
s
t
o
p
s
i
n
t
h
e
S
P
E
D
ar
ch
i
t
ect
u
r
e
w
h
en
e
v
er
i
t
ac-
ces
s
es
t
h
e
d
i
s
k
,
i
t
can
o
n
l
y
g
en
er
at
e
o
n
e
d
i
s
k
r
eq
u
es
t
at
a
Event Dispatcher
Read
Request
Read
Request
Find
File
Find
File
Get
Conn
Accept
Conn
Send Header
Read File
Send Data
Read File
Send Data
Send Header
Fi
g
u
r
e
4
:
Si
n
g
l
e
Pr
o
c
e
s
s
E
v
e
n
t
D
r
i
v
e
n
-
T
h
e
SPE
D
mo
d
e
l
u
s
e
s
a
s
i
n
g
l
e
p
r
o
c
e
s
s
t
o
p
e
r
f
o
r
m
a
l
l
c
l
i
e
n
t
p
r
o
c
e
s
s
-
in
g
a
n
d
d
is
k
a
c
ti
v
ity
in
a
n
e
v
e
n
t-
d
r
i
v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
ch
i
t
ect
u
r
e
s
t
r
iv
es
t
o
p
r
es
er
v
e
t
h
e
ef
fi
-
ci
en
c
y
o
f
t
h
e
S
P
E
D
ar
ch
i
t
ect
u
r
e
o
n
o
p
er
at
i
o
n
s
o
t
h
er
t
h
an
di
s
k
re
a
ds
,
b
ut
a
v
oi
ds
t
he
pe
rform
a
nc
e
probl
e
m
s
s
uf
fe
re
d
by
S
P
E
D
due
t
o
i
na
ppropri
a
t
e
s
upport
f
or
a
s
ync
hronous
di
s
k
r
e
a
ds
i
n
m
a
n
y
ope
r
a
t
i
ng
s
ys
t
e
m
s
.
A
M
P
E
D
a
c
hi
e
v
e
s
th
is
u
s
in
g
o
n
ly
s
u
p
p
o
r
t
th
a
t
is
w
id
e
ly
a
v
a
ila
b
le
in
m
o
d
e
r
n
ope
ra
t
i
ng
s
ys
t
e
m
s
.
In
a
U
N
I
X
s
ys
t
e
m
,
A
M
P
E
D
us
e
s
t
he
s
t
a
nda
rd
non-
bl
oc
ki
ng
read
,
write
,a
n
d
accept
sy
st
e
m
c
a
l
l
s
o
n
so
c
k
e
t
s
a
n
d
p
i
p
e
s,
a
n
d
t
h
e
select
sy
st
e
m
c
a
l
l
t
o
t
e
st
f
o
r
I/
O
c
om
pl
e
t
i
on.
T
he
mmap
ope
r
a
t
i
on
i
s
us
e
d
t
o
a
c
c
e
s
s
da
t
a
from
t
he
fi
l
e
s
ys
t
e
m
a
nd
t
he
mincore
ope
ra
t
i
on
i
s
us
e
d
t
o
c
he
c
k
i
f
a
fi
l
e
i
s
i
n
m
a
i
n
m
e
m
or
y
.
No
t
e
t
h
a
t
t
h
e
h
e
l
p
e
r
s
c
a
n
b
e
i
m
p
l
e
m
e
n
t
e
d
e
i
t
h
e
r
a
s
ke
r
ne
l
t
hr
e
a
ds
w
i
t
hi
n
t
he
m
a
i
n
s
e
r
v
e
r
pr
oc
e
s
s
or
a
s
s
e
p-
ar
at
e
p
r
o
ces
s
es
.
Ev
en
w
h
en
h
el
p
er
s
ar
e
i
m
p
l
emen
t
ed
as
se
p
a
r
a
t
e
p
r
o
c
e
sse
s,
t
h
e
u
se
o
f
mmap
al
l
o
w
s
t
h
e
h
el
p
er
s
to
initia
te
the
r
e
a
d
ing
o
f
a
fi
l
e
from
d
is
k
w
ithout
intro-
duc
i
ng
a
ddi
t
i
ona
l
da
t
a
c
opyi
ng.
In
t
hi
s
c
a
s
e
,
bot
h
t
he
mai
n
s
er
v
er
p
r
o
ces
s
an
d
t
h
e
h
el
p
er
mmap
a r
e
q
u
e
s
t
e
d
fi
l
e
.
Th
e
h
e
l
p
e
r
t
o
u
c
h
e
s
a
l
l
t
h
e
p
a
g
e
s
i
n
i
t
s
m
e
m
o
r
y
m
a
p
p
i
n
g
.
On
c
e
fi
n
i
s
h
e
d
,
i
t
n
o
t
i
fi
e
s
t
h
e
m
a
i
n
s
e
r
v
e
r
p
r
o
c
e
s
s
t
h
a
t
i
t
i
s
no
w
s
a
f
e
t
o
t
ra
ns
m
i
t
t
he
fi
l
e
w
i
t
hout
t
he
r
i
s
k
of
bl
oc
ki
ng.
4
D
e
s
i
gn
c
o
m
p
ar
i
s
o
n
In
t
h
i
s
s
e
c
t
i
o
n
,
w
e
p
re
s
e
n
t
a
q
u
a
l
i
t
a
t
i
v
e
c
o
m
p
a
ri
s
o
n
of
t
he
pe
r
f
or
m
a
nc
e
c
ha
r
a
c
t
e
r
i
s
t
i
c
s
a
nd
pos
s
i
bl
e
opt
i
m
i
z
a
-
tio
n
s
in
th
e
v
a
r
io
u
s
W
e
b
s
e
r
v
e
r
a
r
c
h
ite
c
tu
r
e
s
p
r
e
s
e
n
te
d
in
th
e
p
r
e
v
io
u
s
s
e
c
tio
n
.
Event Dispatcher
Read
Request
Read
Request
Find
File
Find
File
Get
Conn
Accept
Conn
Send Header
Read File
Send Data
Read File
Send Data
Send Header
Helper 1
Helper 2
Helper k
Fi
g
u
r
e
5
:
A
s
y
m
m
e
t
r
i
c
M
u
l
t
i
-
Pr
o
c
e
s
s
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
y
g
en
er
at
e
o
n
e
d
i
s
k
r
eq
u
es
t
at
a
Figures from
Pai
, et al., 1999 “Flash: An efficient and portable Web server”
Multiple processes
Multiple Threads
Single Process Event Driven
Single Process Event Driven with Helpers
Threads
•
Usual model for achieving concurrency
•
Uniform abstraction for single and multiple
cores
•
Concurrency with locks/
mutexes
–
Threads may block, hold locks for long time
•
Easy to reason about
–
Each thread has own stack
•
Strong support from OS, libraries,
debuggers
•
Traditionally, problems with more than a few
100 threads
–
Memory overhead,
O(n
) operations
Performance, Thread
-
based
server
From Welsh, et al., SOSP 2001 “SEDA: An Architecture for Well
-
Conditioned, Scalable
Internet Services
Events
•
Small number of threads, one per CPU
•
Threads do one thing:
while(1) {
get event from queue
Handle event to completion
}
•
Events are network, I/O readiness and
completion, timers, signals
–
Remember select()?
•
Assume event handlers never block
–
Helper threads handle blocking calls, like disk
I/O
Events
•
Many works in the early 2000’s claimed
that events are needed for high
performance servers
–
E.g., Flash,
thttpd
, Zeus, JAWS web servers
•
Indeed, many of today’s fastest servers
are
event
-
driven
–
E.g.,
OKCupid
,
lighttpd
,
nginx
, tornado
Lighttpd
: “Its event
-
driven architecture is optimized for a large number of
parallel connections”
Performance, Event
-
Driven Web
server
From Welsh, et al., SOSP 2001 “SEDA: An Architecture for Well
-
Conditioned, Scalable
Internet Services
Flash Web Server
•
Pai
,
Drushel
,
Zwaenepoel
, 1999
•
Influential work
•
Compared four architectures
–
Multi
-
process servers
–
Multi
-
threaded servers
–
Single
-
process event
-
driven
–
Asymmetric Multi
-
process event driven
•
AMPED was the fastest
Events (cont)
•
Highly efficient code
–
Little or no switching overhead
–
Easy concurrency control
•
Common complaint: hard to program and
reason about
–
For people and tools
•
Main reason:
stack ripping
Events criticism: control flow
Accept
Conn.
Write
Response
Read
File
Read
Request
Pin
Cache
Web Server
Exit
Threads
Events
thread_main(int sock) {
struct session s;
accept_conn(sock, &s);
read_request(&s);
pin_cache(&s);
write_response(&s);
unpin(&s);
}
pin_cache(struct session *s) {
pin(&s);
if( !in_cache(&s) )
read_file(&s);
}
CacheHandler(struct session *s) {
pin(s);
if( !in_cache(s) ) ReadFileHandler.enqueue(s);
else ResponseHandler.enqueue(s);
}
RequestHandler(struct session *s) {
…; CacheHandler.enqueue(s);
}
. . .
ExitHandlerr(struct session *s) {
…; unpin(&s); free_session(s);
}
AcceptHandler(event e) {
struct session *s = new_session(e);
RequestHandler.enqueue(s); }
•
Events obscure control flow
–
For programmers
and
tools
Events criticism: Exceptions
•
Exceptions complicate control flow
–
Harder to understand program flow
–
Cause bugs in cleanup code
Accept
Conn.
Write
Response
Read
File
Read
Request
Pin
Cache
Web Server
Exit
Threads
Events
thread_main(int sock) {
struct session s;
accept_conn(sock, &s);
if( !read_request(&s) )
return;
pin_cache(&s);
write_response(&s);
unpin(&s);
}
pin_cache(struct session *s) {
pin(&s);
if( !in_cache(&s) )
read_file(&s);
}
CacheHandler(struct session *s) {
pin(s);
if( !in_cache(s) ) ReadFileHandler.enqueue(s);
else ResponseHandler.enqueue(s);
}
RequestHandler(struct session *s) {
…; if( error )
return;
CacheHandler.enqueue(s);
}
. . .
ExitHandlerr(struct session *s) {
…;
unpin(&s); free_session(s);
}
AcceptHandler(event e) {
struct session *s = new_session(e);
RequestHandler.enqueue(s); }
Events criticism: State
Management
Threads
Events
thread_main(int sock) {
struct session s;
accept_conn(sock, &s);
if( !read_request(&s) )
return;
pin_cache(&s);
write_response(&s);
unpin(&s);
}
pin_cache(struct session *s) {
pin(&s);
if( !in_cache(&s) )
read_file(&s);
}
CacheHandler(struct session *s) {
pin(s);
if( !in_cache(s) ) ReadFileHandler.enqueue(s);
else ResponseHandler.enqueue(s);
}
RequestHandler(struct session *s) {
…; if( error )
return; CacheHandler.enqueue(s);
}
. . .
ExitHandlerr(struct session *s) {
…; unpin(&s);
free_session(s);
}
AcceptHandler(event e) {
struct session *s = new_session(e);
RequestHandler.enqueue(s); }
Accept
Conn.
Write
Response
Read
File
Read
Request
Pin
Cache
Web Server
Exit
•
Events require manual state management
•
Hard to know when to free
–
Use GC or risk bugs
Usual Arguments
•
Events:
–
Hard to program (stack ripping)
–
Easy to deal with concurrency (cooperative task
management)
•
Shared state is more explicit
–
High performance (low overhead, no switching, no
blocking)
•
Threads
–
Easy to reason about flow, state (automatic stack
management)
–
Hard to deal with concurrency (preemptive task
management)
•
Everything is shared
–
Lower performance (thread switching cost, memory
overhead)
Capriccio (2003)
•
Showed threads can
perform as well as
events
–
Avoid
O(n
) operations
–
Cooperative lightweight
user
-
level threads
•
(still one kernel thread
per core)
–
Asynchronous I/O
•
Handled by the library
–
Variable
-
length stacks
–
The thread library runs
an event
-
based system
underneath!
Requests / Second
Concurrent Tasks
Event-Based Server
Threaded Server
20000
30000
40000
50000
60000
70000
80000
90000
100000
110000
1
10
100
1000
10000
100000
1e+06
Artificial Dichotomy!
•
Old debate! Lauer and Needham, 78
–
Duality between process
-
based and message
-
passing
–
Updated by the Capriccio folks, 2003
•
Performance should be similar
–
No inherent reason for threads to be worse
–
Implementation is key
Threads
Events
Monitors
Exported functions
Call/return and fork/join
Wait on condition variable
Event handler & queue
Events accepted
Send message / await reply
Wait for new messages
Artificial Dichotomy
•
Threads
–
Preemptive multitasking
–
Automatic stack management
•
Events
–
Cooperative multitasking
–
Manual stack management (stack ripping)
•
Adya
, 2002: you can choose your
features!
–
They show that you can have cooperative
multitasking with automatic stack
managment
Adya
, A. et al., 2002. “Cooperative Task Management without Manual Stack
Managementor
, Event
-
driven Programming is Not the Opposite of Threaded
Programming
Threads vs. Events
•
Today you still have to mostly choose
either style (complete packages)
–
Thread
-
based servers very dependent on OS,
threading libraries
•
Some promising directions!
–
TAME allows you to write sequential C++ code
(with some annotations), converts it into event
-
based
–
Scala
(
oo
/functional language that runs on the
JVM) makes threaded and event
-
based code
look almost identical
Popular Event
-
Based
Frameworks
•
libevent
•
libasync
(SFS, SFS
-
light)
•
Javascript
–
All browser code
–
Node.js
at the server side
•
GUI programming
Some available libraries
With material from Igor
Ganichev
Python
•
Rich standard library
–
url/http/ftp/pop/imap/smtp/telnet
–
SocketServer
,
HTTPServer
,
DocXMLRPCServer
,
etc
•
Twisted
–
Very popular
–
Has
a lot
of stuff, but quite modular
–
Event
-
driven, many design patterns. Steep
learning curve…
–
Well maintained and documented
Java
•
Mature RPC library: RMI
•
River: RMI + service discovery, mobile
code
•
Java.NIO
–
High
-
level wrapping of OS primitives
•
Select
-
> Selector . Socket
-
> Channel
–
Good, efficient buffer abstraction
•
Jetty
–
Extensible, event
-
driven framework
–
High
-
performance
–
Avoid unnecessary copies
–
Other side doesn’t have to be in Java
C
•
Sockets!
•
Direct access to what the OS provides
•
Libevent
–
Simple, somewhat portable abstraction of
select() with uniform access to events: I/O,
timers, signals
–
Supports /dev/poll, kqueue(2), event ports,
select(2), poll(2) and epoll(4).
–
Well maintained, actively developed
–
Behind many very high
-
performance servers
•
Memcached
C++
•
Boost.ASIO
–
Clean, lightweight, portable abstraction of
sockets and other features
–
Not a lot of higher
-
level protocol support
–
Has support for both synchronous and
asynchronous operations, threads (from other
parts of Boost)
•
Others: ACE, POCO
ICE
•
Cross
-
language middleware + framework
–
Think twisted + protocol buffers
•
Open source but owned by a company
•
SSL, sync/
async
, threads, resource
allocation, firewall traversal, event
distribution, fault tolerance
•
Supports many languages
–
C++, Java, .NET
-
languages (such as C# or
Visual Basic), Objective
-
C, Python, PHP, and
Ruby
Other “cool” approaches
•
Erlang
,
Scala
, Objective C
–
Support the Actor model: program is a bunch of
actors sending messages to each other
–
Naturally extends to multi
-
core and multiple
machines, as sending messages is the same
•
Go
–
Built for concurrency, uses ‘
Goroutines
’, no
shared state
–
“Don’t share memory to communicate,
communicate to share memory”
Node.js
•
Javascript
server framework
•
Leverages highly efficient Chrome V8
Javascript
JIT runtime
•
Completely event
-
based
•
Many high
-
level libraries
var
http =
require('http
');
http.createServer(function
(
req
, res) {
res.writeHead(200, {'Content
-
Type': 'text/plain'});
res.end('Hello
World
\
n');
}).listen(8124, "127.0.0.1");
console.log('Server
running at http://127.0.0.1:8124/');
Final Assignment
Final Project
•
Tethering IP over 3G
•
Problem: Laptop in need of internet, no Wi
-
Fi
available.
•
On hand: Smartphone with 3G connection.
•
Native applications don’t always allow
custom network programming.
–
iOS
App Store guidelines.
Custom Tethering Solution
•
Websockets
to the rescue!
–
Implemented in browsers.
–
Bi
-
directional, full
-
duplex connection over a
single TCP socket.
–
Modern smartphone browsers have implemented
websockets
.
Implementation
Some questions
•
How to connect phone to laptop?
•
How to encode data?
•
Virtual interfaces: TUN or TAP?
•
Client: setting up routes
•
Server: what to do with the packets you
receive?
Some Resources
•
TUN/TAP Interfaces
–
TunTap
package for Mac OSX
•
Websocket
Server
–
Twisted
•
NAT
–
Scapy
•
Base64 Encoding
–
http://www.ietf.org/rfc/rfc3548.txt
Enter the password to open this PDF file:
File name:
-
File size:
-
Title:
-
Author:
-
Subject:
-
Keywords:
-
Creation Date:
-
Modification Date:
-
Creator:
-
PDF Producer:
-
PDF Version:
-
Page Count:
-
Preparing document for printing…
0%
Σχόλια 0
Συνδεθείτε για να κοινοποιήσετε σχόλιο