My current plan for handling 10k+ connections, will edit as it's improved.
Comments are welcome :)
Idea: Don't block on anything until it's ready. When waiting for I/O, accept more connections.
+Asynchronous I/O.
+Non-blocking sockets.
+Multi-threaded.
+Self contained threads.
+Single thread can handle multiple connections, more threads = more connections
+Only one thread design needed
+No synchronization of threads needed
+Self load balancing threads. ie. Threads with more free cycles will call accept more often.
-/+ One connection will use about 10 KB of memory.
-More complicated (but more awesome too).
-Will likely be a tad slower on many small requests.
struct Data = socket fd, file fd, send_offset, length, 8KB buf(recv, path, url) =
8 + 8 + 8 + 8 + 8192 + 104 + 2000 = 10328 bytes
Storing pointer to struct in epoll user data, no need for extra data structure.
worker-thread pseudocode
top:
accept
epol_ctl( socket fd, read )
epoll_wait ( socket recv, send fds, and file read fds )
socket recv ( if file fd == 0 ):
allocate data mem & add socket fd to data
recv
parse for file & open, store fd in data & create header.
epoll_ctl( file fd, read )
socket send:
send
if done, free data, epoll_ctl delete else inc offset
file read ( if file fd != 0 ):
get info from Data struct: offset, length
read()
update Data, if done remove&close file fd, add socket send fd
goto top
My current plan for handling 10k+ connections, will edit as it's improved.
Comments are welcome :)
Idea: Don't block on anything until it's ready. When waiting for I/O, accept more connections.
+Asynchronous I/O.
+Non-blocking sockets.
+Multi-threaded.
+Self contained threads.
+Single thread can handle multiple connections, more threads = more connections
+Only one thread design needed
+No synchronization of threads needed
+Self load balancing threads. ie. Threads with more free cycles will call accept more often.
-/+ One connection will use about 10 KB of memory.
-More complicated (but more awesome too).
-Will likely be a tad slower on many small requests.
struct Data = socket fd, file fd, send_offset, length, 8KB buf(recv, path, url) =
8 + 8 + 8 + 8 + 8192 + 104 + 2000 = 10328 bytes
Storing pointer to struct in epoll user data, no need for extra data structure.
worker-thread pseudocode