[Libwebsockets] trouble with external POLL array handling

Edwin van den Oetelaar oetelaar.automatisering at gmail.com
Wed Jan 16 22:49:47 CET 2013


I made a mistake with the delete of the fd. (not fixing the lookup table)
I have to give the official credit to my wife (Ellen), who,  while
actually already in bed listening to my comments about the code not
working pointed me to my mistake.
(yes really, and she is not a computer programmer but a first aid instructor)

here is the code for the external poll handling.

=====
#ifdef EXTERNAL_POLL
        /*
         * callbacks for managing the external poll() array appear in
         * protocol 0 callback
         */

    case LWS_CALLBACK_ADD_POLL_FD:

        if (count_pollfds == MAX_POLL_ELEMENTS) {
            fprintf(stderr, "LWS_CALLBACK_ADD_POLL_FD: too many
sockets to track\n");
            return 1;
        }
        assert(fd < MAX_POLL_ELEMENTS);
        assert(count_pollfds < MAX_POLL_ELEMENTS);
        assert(!(count_pollfds < 0));

        fd_lookup[fd] = count_pollfds; // no hashtable anymore
        pollfds[count_pollfds].fd = fd;
        pollfds[count_pollfds].events = (int) (long) len;
        pollfds[count_pollfds++].revents = 0;
        break;

    case LWS_CALLBACK_DEL_POLL_FD:
        m = fd_lookup[fd]; // m is position of fd in pollfds[] array
        if (v) fprintf(stderr, "Removing fd %d at pos %d\n", fd, m);

        assert(!(m < 0));
        count_pollfds--;
        if (count_pollfds) {
            pollfds[m] = pollfds[count_pollfds]; // move last in empty place
            // fix the fd_lookup table
            // the fd can now be found at location m
            fd_lookup[pollfds[count_pollfds].fd] = m;
            pollfds[count_pollfds].fd = -1; // invalidate last item
        }
        fd_lookup[fd] = -1; // invalidate
        break;

    case LWS_CALLBACK_SET_MODE_POLL_FD:
        if (v) fprintf(stderr, "Set Poll mode fd=%d mode=%d\n", fd, (int) len);
        m = fd_lookup[fd]; // m is position of fd in pollfds[] array
        pollfds[m].events |= (int) (long) len;
        break;

    case LWS_CALLBACK_CLEAR_MODE_POLL_FD:
        m = fd_lookup[fd]; // m is position of fd in pollfds[] array
        if (v) fprintf(stderr, "Clear Poll mode fd=%d mode=%d\n", fd,
(int) len);
        pollfds[m].events &= ~(int) (long) len;
        break;
#endif

=====



The new stats: can it be done any faster?

Finished 100000 requests


Server Software:        libwebsockets
Server Hostname:        localhost
Server Port:            8088

Document Path:          /
Document Length:        2211 bytes

Concurrency Level:      100
Time taken for tests:   5.238 seconds
Complete requests:      100000
Failed requests:        0
Write errors:           0
Total transferred:      230071300 bytes
HTML transferred:       221168541 bytes
Requests per second:    19090.60 [#/sec] (mean)
Time per request:       5.238 [ms] (mean)
Time per request:       0.052 [ms] (mean, across all concurrent requests)
Transfer rate:          42892.58 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    2   0.4      2       9
Processing:     1    3   0.7      3      14
Waiting:        1    3   0.7      3      14
Total:          3    5   0.7      5      15

Percentage of the requests served within a certain time (ms)
  50%      5
  66%      5
  75%      5
  80%      5
  90%      6
  95%      6
  98%      6
  99%      7
 100%     15 (longest request)



More information about the Libwebsockets mailing list