comparing and evaluating epoll, select and poll event mechanisms

22
http://gelato.uwaterloo.ca Comparing and Evaluating epoll, select and poll Event Mechanisms Louay Gammo, Tim Brecht, Amol Shukla, and David Pariag

Upload: ian

Post on 12-Nov-2014

894 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Comparing and Evaluating epoll, select and poll Event Mechanisms

http://gelato.uwaterloo.ca

Comparing and Evaluating epoll, select and poll Event Mechanisms

Louay Gammo, Tim Brecht,Amol Shukla, and David Pariag

Page 2: Comparing and Evaluating epoll, select and poll Event Mechanisms

2

The Problem and Goals

Requests/sec

Res

pons

es/s

ec• Increase peak performance• Sustain peak performance under overload• Handle large numbers of connections

Better understand apps and interaction with kernel

Page 3: Comparing and Evaluating epoll, select and poll Event Mechanisms

3

Server Phases

n = get new connectionswhile (accept())

process events / connections

get events select(),poll(),epoll_wait()

read() write()/sendfile()

Page 4: Comparing and Evaluating epoll, select and poll Event Mechanisms

4

select and pollFD_SET(fd, &readable);rdfds = readable; wrfds = writable;n = select(max, rdfds, wrfds, exfds, &tout);if (FD_ISSET(fd, rdfds)) { read }FD_SET(fd, &writable); FD_CLR(fd, &readable);

array[i].events = POLLIN;n = poll(array, max, &tout);if (array[i].revents & POLLIN) { read }array[i].events = POLLOUT;

Page 5: Comparing and Evaluating epoll, select and poll Event Mechanisms

5

epoll

epfd = epoll_create(max_fds);

evt.data.fd = fd;evt.events = EPOLLIN;epoll_ctl(epfd, EPOLL_CTL_ADD, fd, &evt);

epoll_wait(epfd, results, max_fd, tout);

evt.data.fd = fd;evt.events = EPOLLOUT;epoll_ctl(epfd, EPOLL_CTL_MOD, fd, &evt);

Page 6: Comparing and Evaluating epoll, select and poll Event Mechanisms

6

Motivation

• Simple 1 byte file workload (hammer the event mechanism)

Page 7: Comparing and Evaluating epoll, select and poll Event Mechanisms

7

Motivation

• Simple 1 byte file workload (hammer the event mechanism)

22,000 req/sec

Page 8: Comparing and Evaluating epoll, select and poll Event Mechanisms

8

Motivation: gprof comparison

3.432.703.43sendfile3.613.343.66fcntl5.705.065.98write

10.209.5110.08accept10.689.1311.17setsockopt

16.34epoll_clt7.15epoll_wait

13.32poll13.33select

14.7914.0514.90close20.9720.9521.51readpollepoll-LTselectSyscall

14,708 13,026 13,671replies/sec

Page 9: Comparing and Evaluating epoll, select and poll Event Mechanisms

9

Reducing epoll_ctl() overhead• Don’t modify interests (epoll2)

– add/remove interest at time of accept and close– less epoll_ctl but more epoll_wait

• Aggregate System Calls (epoll_ctlv)– system call -- uses an array of fds/interest sets– one system call, many changes (ala readv/writev)

• Edge-triggered (epoll-ET)– only get events when there is a change on the fd– requires tracking state of the fd in application

Page 10: Comparing and Evaluating epoll, select and poll Event Mechanisms

10

Reducing epoll_ctlv calls

Page 11: Comparing and Evaluating epoll, select and poll Event Mechanisms

11

Reducing epoll_ctlv calls

Page 12: Comparing and Evaluating epoll, select and poll Event Mechanisms

12

Reducing epoll_ctlv calls

Page 13: Comparing and Evaluating epoll, select and poll Event Mechanisms

13

Reducing epoll_ctlv calls

22,000 req/sec

Page 14: Comparing and Evaluating epoll, select and poll Event Mechanisms

14

gprof results @ 22,000 req/s

3.912.713.002.70sendfile3.343.373.143.34fcntl5.315.104.135.06write9.309.769.059.51accept9.089.137.579.13sockopt

9.28epoll_ctlv11.065.9810.2716.34epoll_ctl6.526.0112.567.15epoll_wait

14.1414.9013.0214.05close22.1921.4120.0820.95read

edgectlvepoll2epollSyscall

13,026 13,598 13,343 13,665replies/sec

Page 15: Comparing and Evaluating epoll, select and poll Event Mechanisms

15

gprof results @ 22,000 req/s

3.912.713.002.70sendfile3.343.373.143.34fcntl5.315.104.135.06write9.309.769.059.51accept9.089.137.579.13sockopt

9.28epoll_ctlv11.065.9810.2716.34epoll_ctl

6.526.0112.567.15epoll_wait14.1414.9013.0214.05close22.1921.4120.0820.95read

edgectlvepoll2epollSyscall

13,026 13,598 13,343 13,665replies/sec

Page 16: Comparing and Evaluating epoll, select and poll Event Mechanisms

16

gprof results @ 22,000 req/s

3.912.713.002.70sendfile3.343.373.143.34fcntl5.315.104.135.06write9.309.769.059.51accept9.089.137.579.13sockopt

9.28epoll_ctlv11.065.9810.2716.34epoll_ctl6.526.0112.567.15epoll_wait

14.1414.9013.0214.05close22.1921.4120.0820.95read

edgectlvepoll2epollSyscall

13,026 13,598 13,343 13,665replies/sec

Page 17: Comparing and Evaluating epoll, select and poll Event Mechanisms

17

gprof results @ 22,000 req/s

3.912.713.002.70sendfile3.343.373.143.34fcntl5.315.104.135.06write9.309.769.059.51accept9.089.137.579.13sockopt

9.28epoll_ctlv11.065.9810.2716.34epoll_ctl6.526.0112.567.15epoll_wait

14.1414.9013.0214.05close22.1921.4120.0820.95read

edgectlvepoll2epollSyscall

13,026 13,598 13,343 13,665replies/sec

Page 18: Comparing and Evaluating epoll, select and poll Event Mechanisms

18

1 Byte File: 10,000 idle conns

Page 19: Comparing and Evaluating epoll, select and poll Event Mechanisms

19

SPECweb99-like Workload

Page 20: Comparing and Evaluating epoll, select and poll Event Mechanisms

20

SPECweb99-like: 10,000 idle conns

Page 21: Comparing and Evaluating epoll, select and poll Event Mechanisms

21

Itanium Results: 1 byte file

Warning: appear to be problems with poll/epoll on IA64(we are working with people to resolve them)

Page 22: Comparing and Evaluating epoll, select and poll Event Mechanisms

22

Discussion

• Reducing epoll_ctl costs did not improve tput– epoll2 does quite well despite extra costs– epoll-LT/ET quite similar performance

• select and poll do well on some workloads

– multiple accepts reduce event dispatch overheads

• Need better understanding– Once kernel bug is fixed use perf tools on IA64

• How to better represent Internet/WAN wloads– idle connections not very realistic ???