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


 ___________________________________________________ 
 您的生活即時通 - 溝通、娛樂、生活、工作一次搞定! 
 http://messenger.yahoo.com.tw/
_______________________________________________
Libevent-users mailing list
Libevent-users@monkey.org
http://monkey.org/mailman/listinfo/libevent-users

Reply via email to