Ignore:
File:
1 edited

Legend:

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

    r32d1383 r3f95dab  
    1414#include "filecache.hfa"
    1515
    16 static const unsigned long long period = 5_000_000;
     16static const unsigned long long period = 50_000_000;
    1717
    1818//=============================================================================================
     
    3333
    3434                // if we are done, break out of the loop
    35                 if( closed ) {
    36                         if( code != OK200 ) this.stats.sendfile.error++;
    37                         break REQUEST;
    38                 }
     35                if( closed ) break REQUEST;
    3936
    4037                // If this wasn't a request retrun 400
    4138                if( code != OK200 ) {
    42                         abort | "=== Invalid Request :" | code_val(code) | "===";
    43                         // answer_error(fd, code);
    44                         // continue REQUEST;
    45                 }
    46 
    47                 // if(0 == strncmp(file, "plaintext", min(name_size, sizeof("plaintext") ))) {
    48                 //      if( options.log ) mutex(sout) sout | "=== Request for /plaintext ===";
    49 
    50                 //      int ret = answer_plaintext(fd);
    51                 //      if( ret == -ECONNRESET ) { this.stats.sendfile.error++; break REQUEST; }
    52 
    53                 //      if( options.log ) mutex(sout) sout | "=== Answer sent ===";
    54                 //      continue REQUEST;
    55                 // }
    56 
    57                 // if(0 == strncmp(file, "ping", min(name_size, sizeof("ping") ))) {
    58                 //      if( options.log ) mutex(sout) sout | "=== Request for /ping ===";
    59 
    60                 //      // Send the header
    61                 //      int ret = answer_empty(fd);
    62                 //      if( ret == -ECONNRESET ) { this.stats.sendfile.error++; break REQUEST; }
    63 
    64                 //      if( options.log ) mutex(sout) sout | "=== Answer sent ===";
    65                 //      continue REQUEST;
    66                 // }
     39                        sout | "=== Invalid Request :" | code_val(code) | "===";
     40                        answer_error(fd, code);
     41                        continue REQUEST;
     42                }
     43
     44                if(0 == strncmp(file, "plaintext", min(name_size, sizeof("plaintext") ))) {
     45                        if( options.log ) mutex(sout) sout | "=== Request for /plaintext ===";
     46
     47                        int ret = answer_plaintext(fd);
     48                        if( ret == -ECONNRESET ) break REQUEST;
     49
     50                        if( options.log ) mutex(sout) sout | "=== Answer sent ===";
     51                        continue REQUEST;
     52                }
     53
     54                if(0 == strncmp(file, "ping", min(name_size, sizeof("ping") ))) {
     55                        if( options.log ) mutex(sout) sout | "=== Request for /ping ===";
     56
     57                        // Send the header
     58                        int ret = answer_empty(fd);
     59                        if( ret == -ECONNRESET ) break REQUEST;
     60
     61                        if( options.log ) mutex(sout) sout | "=== Answer sent ===";
     62                        continue REQUEST;
     63                }
    6764
    6865                if( options.log ) {
     
    7370
    7471                if( !options.file_cache.path ) {
    75                         // if( options.log ) {
    76                                 serr | "=== File Not Found (" | nonl;
    77                                 write(serr, file, name_size);
    78                                 serr | ") ===";
    79                                 abort();
    80                         // }
    81                         // answer_error(fd, E405);
    82                         // continue REQUEST;
     72                        if( options.log ) {
     73                                sout | "=== File Not Found (" | nonl;
     74                                write(sout, file, name_size);
     75                                sout | ") ===";
     76                        }
     77                        answer_error(fd, E405);
     78                        continue REQUEST;
    8379                }
    8480
     
    9086                // If we can't find the file, return 404
    9187                if( ans_fd < 0 ) {
    92                         // if( options.log ) {
    93                                 serr | "=== File Not Found 2 (" | nonl;
    94                                 write(serr, file, name_size);
    95                                 serr | ") ===";
    96                                 abort();
    97                         // }
    98                         // answer_error(fd, E404);
    99                         // continue REQUEST;
     88                        if( options.log ) {
     89                                sout | "=== File Not Found (" | nonl;
     90                                write(sout, file, name_size);
     91                                sout | ") ===";
     92                        }
     93                        answer_error(fd, E404);
     94                        continue REQUEST;
    10095                }
    10196
     
    10398                int ret = answer_sendfile( this.pipe, fd, ans_fd, count, this.stats.sendfile );
    10499                if(ret < 0) {
    105                         if( ret == -ECONNABORTED ) { this.stats.sendfile.error++; break REQUEST; }
    106                         if( ret == -ECONNRESET ) { this.stats.sendfile.error++; break REQUEST; }
    107                         if( ret == -EPIPE ) { this.stats.sendfile.error++; break REQUEST; }
    108                         if( ret == -EBADF ) { this.stats.sendfile.error++; break REQUEST; }
    109                         abort( "answer sendfile error: %d (%d) %s\n", ret, (int)errno, strerror(errno) );
     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) );
    110104                }
    111105
     
    113107        }
    114108
    115         this.stats.sendfile.close++;
    116 
    117109        if (stats_thrd) {
    118                 // unsigned long long next = rdtscl();
    119                 // if(next > (last + period)) {
     110                unsigned long long next = rdtscl();
     111                if(next > (last + period)) {
    120112                        if(try_lock(stats_thrd->stats.lock __cfaabi_dbg_ctx2)) {
    121113                                push(this.stats.sendfile, stats_thrd->stats.send);
    122114                                unlock(stats_thrd->stats.lock);
    123                                 // last = next;
    124                         }
    125                 // }
     115                                last = next;
     116                        }
     117                }
    126118        }
    127119}
     
    152144                if(this.done) break;
    153145
    154                 this.stats.accepts++;
    155                 if (stats_thrd && try_lock(stats_thrd->stats.lock)) {
    156                         push(this.stats, stats_thrd->stats.accpt);
    157                         unlock(stats_thrd->stats.lock);
    158                 }
    159 
    160146                if( options.log ) mutex(sout) sout | "=== New connection" | fd | "" | ", waiting for requests ===";
    161147                size_t len = options.socket.buflen;
     
    163149                handle_connection( this.conn, fd, buffer, len, 0p, last );
    164150                this.conn.stats.sendfile.maxfd = max(this.conn.stats.sendfile.maxfd, fd);
     151                this.conn.stats.sendfile.close++;
    165152
    166153                if( options.log ) mutex(sout) sout | "=== Connection closed ===";
     
    185172        /* paranoid */ assert( this.conn.pipe[1] != -1 );
    186173        this.conn.stats.sendfile.maxfd = max(this.conn.pipe[0], this.conn.pipe[1]);
    187         // this.conn.stats.sendfile.maxfd = 0;
    188174        for() {
    189175                size_t len = options.socket.buflen;
     
    234220                p = pop(*this.queue);
    235221                if(p) break;
    236                 // abort( "Too few threads" );
    237222                yield();
    238223                this.stats.creates++;
     
    303288
    304289                if (stats_thrd) {
    305                         // unsigned long long next = rdtscl();
    306                         // if(next > (last + period)) {
     290                        unsigned long long next = rdtscl();
     291                        if(next > (last + period)) {
    307292                                if(try_lock(stats_thrd->stats.lock)) {
    308293                                        push(this.stats, stats_thrd->stats.accpt);
    309294                                        unlock(stats_thrd->stats.lock);
    310                                         // last = next;
     295                                        last = next;
    311296                                }
    312                         // }
     297                        }
    313298                }
    314299
Note: See TracChangeset for help on using the changeset viewer.