>"While other data structures are possible and I vaguely plan some minor 
optimisations"


  I'm very happy to hear what you said! Because every optimization of 
Timer makes it easy for developers to use without having to hold hands in some 
cases (I wrote a lot of code for this).


  I mentioned in my email last year: "About the choice of the data 
structure of the timer watcher". But I didn't get a reply, I want to 
communicate with you about this possibility here.


  In general, we will use the following code to reflect when a network 
connection should be closed:


  static void timer_cb(...) {


    ev_io_stop(...);


  }




  static void io_cb(...) {


    ev_timer_stop(...);


  }


  static void listet_socket (int sock, int events, int timeout, int 
repeats, void* data) {


    io->data = data;
    ev_io_init(io, sock, io_cb, READ or write);
    ev_io_start(loop, io);


    timer->data = data;
    ev_timer_init(timer, timer_cb, timeout, repeats);
    ev_timer_start(loop, io);


    ....


  }


  Of course, there is a simpler "ev_once" available. But when managing 
more than 100,000 network connections, the overhead of the data structure 
itself already occupies a very high user space.


  My current solution is the same as what you said: "Once you need to stop 
the timer, mark it in timer-> data!", Wait for the real timeout before 
calling ev_timer_stop to stop it.


  The modified code looks like this:


  static void timer_cb(...) {


    if (timer->data->closed == 1) {
      ev_timer_again(...); // only need to stop timer.
      return ;
    }


    ev_timer_again(...);


    ev_io_stop(...);


    ...


  }


  static void io_cb(...) {


    // ev_timer_stop(...); before


    timer->data->closed = 1; // now


    ..


  }


  But obviously, this makes the code we write gradually less and less 
readable.


  Can libev provide a "painless" way for developers to use 
"ev_timer_start" at will without having to consider using "trick" to simplify 
the complexity of the algorithm?


  I have observed that a timer called "Timer-wheel" is provided in the 
Linux kernel, and its algorithm complexity is currently constant. This may be a 
good reference.


  Have you considered optimizing by changing the data structure, or do you 
still have other "killer" ways to optimize? Will this affect the stability?


  
_______________________________________________
libev mailing list
[email protected]
http://lists.schmorp.de/mailman/listinfo/libev

Reply via email to