<div>Hi,</div> <div>Is it normally that high cost function call issue about event_queue_remove()?<BR>I profiles my program with gprof. I found the most spent time function call is event_queue_remove().</div> <div>However, I only remove events when connection is closed (conn_drop()).<BR>There are two types events with flag EV_WRITE and (EV_READ | EV_PERSIST) in my program. And, there are about 250 connections and 250*2 events (read and write fd).</div> <div>========================================================<BR>[Pseudo Code]</div> <div>static void conn_drop(struct conn *c)<BR>{<BR> event_del(&c->read_event);<BR> event_del(&c->write_event);<BR> ...<BR>}</div> <div>static void conn_read(int fd, short what, void *d)<BR>{<BR> struct conn *c = (struct conn*) d;<BR> if( read successfully )<BR> {<BR> //do something<BR> if( we need reply in this time
)<BR> event_add(&c->write_event, NULL);<BR> }<BR> else conn_drop();</div> <div>}</div> <div>static void conn_write(int fd, short what, void *d)<BR>{<BR> struct conn *c = (struct conn*) d;<BR> if( write successfully )<BR> {<BR> //do something<BR> }</div> <div> else conn_drop(); // never occur in this test</div> <div> if( write was not completed)<BR> event_add(&c->write_event, NULL); // reschedle</div> <div>}</div> <div>void accept_connection()<BR>{<BR> ...<BR> struct conn *c = new (struct conn);<BR> event_set(&c->read_event, c->fd, EV_READ | EV_PERSIST, conn_read, c);<BR> event_add(&c->read_event, NULL);<BR> event_set(&c->write_event, c->fd, EV_WRITE, conn_write, c);<BR>}</div> <div>========================================================<BR>[ result of gprof are listed below]</div> <div>Each sample
counts as 0.01 seconds. (no list all!)<BR> % cumulative self self total <BR> time seconds seconds calls s/call s/call name <BR> 8.65 0.34 0.34 85441 0.00 0.00 event_queue_remove (No.1)<BR> 5.85 0.57 0.23 GetResource() (No.2)<BR> 3.05 1.91 0.12
1225 0.00 0.00 epoll_dispatch<BR> 1.40 2.62 0.06 30608 0.00 0.00 conn_write(int, short, void*)<BR> 1.02 2.89 0.04 23800 0.00 0.00 conn_read(int, short, void*)<BR> 0.89 3.04 0.04 85732 0.00 0.00 event_queue_insert<BR> 0.64 3.36 0.03 58045 0.00 0.00 event_add<BR> 0.25 3.73 0.01 76
0.00 0.00 conn_drop(connection*, char const*)<BR> 0.25 3.76 0.01 1 0.01 2.00 event_base_loop<BR> 0.00 3.93 0.00 30771 0.00 0.00 event_del<BR> 0.00 3.93 0.00 328 0.00 0.00 server_accept(int, short, void*)<BR>========================================================<BR> Call graph (explanation follows)</div> <div>granularity: each sample hit covers 2 byte(s) for 0.25% of 3.93 seconds</div> <div>index % time self children
called name<BR>-----------------------------------------------<BR> 0.01 1.99 1/1 event_loop [3]<BR>[4] 50.8 0.01 1.99 1 event_base_loop [4]<BR> 0.04 1.37 23800/23800 conn_read(int, short, void*) [5]<BR> 0.12 0.15 1225/1225 epoll_dispatch
[14]<BR> 0.22 0.00 54756/85441 event_queue_remove [13]<BR> 0.06 0.00 30608/30608 conn_write(int, short, void*) [37]<BR> 0.00 0.00 10/30771 event_del [24]<BR> 0.00 0.00 10/85732 event_queue_insert [46]<BR> 0.00
0.00 1225/2450 evsignal_recalc [160]<BR> 0.00 0.00 3675/3687 gettime [170]<BR> 0.00 0.00 2450/2450 event_tree_RB_MINMAX [171]<BR> 0.00 0.00 1225/1225 epoll_recalc [172]<BR> 0.00 0.00 10/10 event_tree_RB_NEXT
[177]<BR> 0.00 0.00 10/10 event_tree_RB_REMOVE [178]<BR> 0.00 0.00 10/54780 event_active [169]<BR>-----------------------------------------------<BR> 0.12 0.00 30685/85441 event_del [24]<BR> 0.22 0.00 54756/85441 event_base_loop [4]<BR>[13] 8.7 0.34
0.00 85441 event_queue_remove [13]<BR>-----------------------------------------------<BR> 0.00 0.00 10/30771 event_base_loop [4]<BR> 0.00 0.00 152/30771 conn_drop(connection*, char const*) [77]<BR> 0.00 0.13 30609/30771 epoll_dispatch [14]<BR>[24] 3.4 0.00 0.13 30771 event_del
[24]<BR> 0.12 0.00 30685/85441 event_queue_remove [13]<BR> 0.01 0.00 30685/30685 epoll_del [83]<BR>-----------------------------------------------<BR></div><p> ___________________________________________________ <br> 您的生活即時通 - 溝通、娛樂、生活、工作一次搞定! <br> http://messenger.yahoo.com.tw/