Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • benchmark/io/http/worker.cfa

    r3f95dab r07997cd  
    1313#include "protocol.hfa"
    1414#include "filecache.hfa"
    15 
    16 static const unsigned long long period = 50_000_000;
    1715
    1816//=============================================================================================
     
    9795                // Send the desired file
    9896                int ret = answer_sendfile( this.pipe, fd, ans_fd, count, this.stats.sendfile );
    99                 if(ret < 0) {
    100                         if( ret == -ECONNABORTED ) break REQUEST;
    101                         if( ret == -ECONNRESET ) break REQUEST;
    102                         if( ret == -EPIPE ) break REQUEST;
    103                         abort( "sendfile error: %d (%d) %s\n", ret, (int)errno, strerror(errno) );
    104                 }
     97                if( ret == -ECONNRESET ) break REQUEST;
    10598
    10699                if( options.log ) mutex(sout) sout | "=== Answer sent ===";
     
    109102        if (stats_thrd) {
    110103                unsigned long long next = rdtscl();
    111                 if(next > (last + period)) {
     104                if(next > (last + 500000000)) {
    112105                        if(try_lock(stats_thrd->stats.lock __cfaabi_dbg_ctx2)) {
    113106                                push(this.stats.sendfile, stats_thrd->stats.send);
     
    148141                char buffer[len];
    149142                handle_connection( this.conn, fd, buffer, len, 0p, last );
    150                 this.conn.stats.sendfile.maxfd = max(this.conn.stats.sendfile.maxfd, fd);
    151                 this.conn.stats.sendfile.close++;
    152143
    153144                if( options.log ) mutex(sout) sout | "=== Connection closed ===";
     
    171162        /* paranoid */ assert( this.conn.pipe[0] != -1 );
    172163        /* paranoid */ assert( this.conn.pipe[1] != -1 );
    173         this.conn.stats.sendfile.maxfd = max(this.conn.pipe[0], this.conn.pipe[1]);
    174164        for() {
    175165                size_t len = options.socket.buflen;
     
    183173                if( options.log ) mutex(sout) sout | "=== Waiting new connection ===";
    184174                handle_connection( this.conn, p.out.fd, buffer, len, &p.f, last );
     175
     176                if( options.log ) mutex(sout) sout | "=== Connection closed ===";
    185177                if(this.done) break;
    186                 this.conn.stats.sendfile.maxfd = max(this.conn.stats.sendfile.maxfd, p.out.fd);
    187                 this.conn.stats.sendfile.close++;
    188 
    189                 if( options.log ) mutex(sout) sout | "=== Connection closed ===";
    190         }
    191 
    192         lock(stats_thrd->stats.lock __cfaabi_dbg_ctx2);
    193         push(this.conn.stats.sendfile, stats_thrd->stats.send);
    194         unlock(stats_thrd->stats.lock);
     178        }
    195179}
    196180
     
    214198
    215199static inline void push_connection( Acceptor & this, int fd ) {
    216         this.stats.accepts++;
    217200        PendingRead * p = 0p;
    218201        for() {
     
    229212
    230213// #define ACCEPT_SPIN
    231 #define ACCEPT_ONE
    232 // #define ACCEPT_MANY
     214#define ACCEPT_MANY
    233215
    234216void main( Acceptor & this ) {
     
    250232                        abort( "accept error: (%d) %s\n", (int)errno, strerror(errno) );
    251233                }
     234                this.stats.accepts++;
    252235
    253236                if(this.done) return;
     
    259242                if (stats_thrd) {
    260243                        unsigned long long next = rdtscl();
    261                         if(next > (last + period)) {
    262                                 if(try_lock(stats_thrd->stats.lock)) {
    263                                         push(this.stats, stats_thrd->stats.accpt);
    264                                         unlock(stats_thrd->stats.lock);
    265                                         last = next;
    266                                 }
    267                         }
    268                 }
    269 
    270                 if( options.log ) sout | "=== Accepting connection ===";
    271         }
    272 
    273 #elif defined(ACCEPT_ONE)
    274         if( options.log ) sout | "=== Accepting connection ===";
    275         for() {
    276                 int fd = cfa_accept4(this.sockfd, this.[addr, addrlen, flags], 0);
    277                 if(fd < 0) {
    278                         if( errno == ECONNABORTED ) break;
    279                         if( this.done && (errno == EINVAL || errno == EBADF) ) break;
    280                         abort( "accept error: (%d) %s\n", (int)errno, strerror(errno) );
    281                 }
    282 
    283                 if(this.done) return;
    284 
    285                 if( options.log ) sout | "=== New connection" | fd | "" | ", waiting for requests ===";
    286 
    287                 if(fd) push_connection(this, fd);
    288 
    289                 if (stats_thrd) {
    290                         unsigned long long next = rdtscl();
    291                         if(next > (last + period)) {
     244                        if(next > (last + 500000000)) {
    292245                                if(try_lock(stats_thrd->stats.lock)) {
    293246                                        push(this.stats, stats_thrd->stats.accpt);
     
    316269                if (stats_thrd) {
    317270                        unsigned long long next = rdtscl();
    318                         if(next > (last + period)) {
     271                        if(next > (last + 500000000)) {
    319272                                if(try_lock(stats_thrd->stats.lock __cfaabi_dbg_ctx2)) {
    320273                                        push(this.stats, stats_thrd->stats.accpt);
     
    331284                                int fd = get_res(res);
    332285                                reset(res);
     286                                this.stats.accepts++;
    333287                                if(fd < 0) {
    334288                                        if( errno == ECONNABORTED ) continue;
     
    365319#error no accept algorithm specified
    366320#endif
    367         lock(stats_thrd->stats.lock);
    368         push(this.stats, stats_thrd->stats.accpt);
    369         unlock(stats_thrd->stats.lock);
    370 }
     321}
Note: See TracChangeset for help on using the changeset viewer.