Changeset 6e16301 for lib


Ignore:
Timestamp:
11/01/17 10:24:26 (3 years ago)
Author:
Shane Alcock <salcock@…>
Branches:
cachetimestamps, develop, dpdk-ndag, etsilive, master, ndag_format, rc-4.0.2, rc-4.0.3, rc-4.0.4, ringdecrementfix, ringperformance
Children:
8fa0167
Parents:
ea75ec2
Message:

Try to avoid selecting() if all socket buffers have data available.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • lib/format_ndag.c

    rea75ec2 r6e16301  
    638638
    639639        fd_set allgroups;
    640         int maxfd, i, ret, readybufs;
     640        int maxfd, i, ret, readybufs, availsocks;
    641641        struct timeval timeout;
    642642
    643         FD_ZERO(&allgroups);
    644643        maxfd = 0;
    645644        timeout.tv_sec = 0;
     
    650649         * port.
    651650         */
     651
     652        readybufs = 0;
     653        availsocks = 0;
    652654
    653655        for (i = 0; i < rt->sourcecount; i ++) {
     
    657659                                maxfd = rt->sources[i].sock;
    658660                        }
    659                 }
    660         }
    661 
     661                        availsocks += 1;
     662                } else if (rt->sources[i].sock != -1) {
     663                        readybufs += 1;
     664                        availsocks += 1;
     665                }
     666        }
     667
     668        /* If all of our sockets already have data sitting in their
     669         * buffers then we can save ourselves some 'select'ing.
     670         */
     671        if (availsocks == readybufs) {
     672                return readybufs;
     673        }
     674
     675        /* Otherwise, at least one active socket has an empty buffer so
     676         * we better try to read some data from those sockets (just in
     677         * case the correct 'next' packet is waiting on one of those
     678         * sockets.
     679         */
     680        FD_ZERO(&allgroups);
    662681        if (select(maxfd + 1, &allgroups, NULL, NULL, &timeout) < 0) {
    663682                fprintf(stderr, "Error waiting to receive records: %s\n",
     
    666685        }
    667686
    668         readybufs = 0;
    669687
    670688        for (i = 0; i < rt->sourcecount; i ++) {
Note: See TracChangeset for help on using the changeset viewer.