Changes in benchmark/io/http/worker.cfa [0f1336c:07997cd]
- File:
-
- 1 edited
-
benchmark/io/http/worker.cfa (modified) (17 diffs)
Legend:
- Unmodified
- Added
- Removed
-
benchmark/io/http/worker.cfa
r0f1336c r07997cd 14 14 #include "filecache.hfa" 15 15 16 static const unsigned long long period = 5_000_000;17 18 16 //============================================================================================= 19 17 // Generic connection handling … … 33 31 34 32 // if we are done, break out of the loop 35 if( closed ) { 36 if( code != OK200 ) this.stats.sendfile.error++; 37 break REQUEST; 38 } 33 if( closed ) break REQUEST; 39 34 40 35 // If this wasn't a request retrun 400 41 36 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 header61 //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 //}37 sout | "=== Invalid Request :" | code_val(code) | "==="; 38 answer_error(fd, code); 39 continue REQUEST; 40 } 41 42 if(0 == strncmp(file, "plaintext", min(name_size, sizeof("plaintext") ))) { 43 if( options.log ) mutex(sout) sout | "=== Request for /plaintext ==="; 44 45 int ret = answer_plaintext(fd); 46 if( ret == -ECONNRESET ) break REQUEST; 47 48 if( options.log ) mutex(sout) sout | "=== Answer sent ==="; 49 continue REQUEST; 50 } 51 52 if(0 == strncmp(file, "ping", min(name_size, sizeof("ping") ))) { 53 if( options.log ) mutex(sout) sout | "=== Request for /ping ==="; 54 55 // Send the header 56 int ret = answer_empty(fd); 57 if( ret == -ECONNRESET ) break REQUEST; 58 59 if( options.log ) mutex(sout) sout | "=== Answer sent ==="; 60 continue REQUEST; 61 } 67 62 68 63 if( options.log ) { … … 73 68 74 69 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; 70 if( options.log ) { 71 sout | "=== File Not Found (" | nonl; 72 write(sout, file, name_size); 73 sout | ") ==="; 74 } 75 answer_error(fd, E405); 76 continue REQUEST; 83 77 } 84 78 … … 90 84 // If we can't find the file, return 404 91 85 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; 86 if( options.log ) { 87 sout | "=== File Not Found (" | nonl; 88 write(sout, file, name_size); 89 sout | ") ==="; 90 } 91 answer_error(fd, E404); 92 continue REQUEST; 100 93 } 101 94 102 95 // Send the desired file 103 96 int ret = answer_sendfile( this.pipe, fd, ans_fd, count, this.stats.sendfile ); 104 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) ); 110 } 97 if( ret == -ECONNRESET ) break REQUEST; 111 98 112 99 if( options.log ) mutex(sout) sout | "=== Answer sent ==="; 113 100 } 114 101 115 this.stats.sendfile.close++;116 117 102 if (stats_thrd) { 118 //unsigned long long next = rdtscl();119 // if(next > (last + period)) {103 unsigned long long next = rdtscl(); 104 if(next > (last + 500000000)) { 120 105 if(try_lock(stats_thrd->stats.lock __cfaabi_dbg_ctx2)) { 121 106 push(this.stats.sendfile, stats_thrd->stats.send); 122 107 unlock(stats_thrd->stats.lock); 123 //last = next;124 } 125 //}108 last = next; 109 } 110 } 126 111 } 127 112 } … … 145 130 if( options.log ) mutex(sout) sout | "=== Accepting connection ==="; 146 131 int fd = cfa_accept4( this.sockfd, this.[addr, addrlen, flags], CFA_IO_LAZY ); 147 if(fd < =0) {132 if(fd < 0) { 148 133 if( errno == ECONNABORTED ) break; 149 134 if( this.done && (errno == EINVAL || errno == EBADF) ) break; 150 abort( "accept error %d: (%d) %s\n", fd, (int)errno, strerror(errno) );135 abort( "accept error: (%d) %s\n", (int)errno, strerror(errno) ); 151 136 } 152 137 if(this.done) break; 153 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 138 160 139 if( options.log ) mutex(sout) sout | "=== New connection" | fd | "" | ", waiting for requests ==="; … … 162 141 char buffer[len]; 163 142 handle_connection( this.conn, fd, buffer, len, 0p, last ); 164 this.conn.stats.sendfile.maxfd = max(this.conn.stats.sendfile.maxfd, fd);165 143 166 144 if( options.log ) mutex(sout) sout | "=== Connection closed ==="; … … 184 162 /* paranoid */ assert( this.conn.pipe[0] != -1 ); 185 163 /* paranoid */ assert( this.conn.pipe[1] != -1 ); 186 this.conn.stats.sendfile.maxfd = max(this.conn.pipe[0], this.conn.pipe[1]);187 // this.conn.stats.sendfile.maxfd = 0;188 164 for() { 189 165 size_t len = options.socket.buflen; … … 197 173 if( options.log ) mutex(sout) sout | "=== Waiting new connection ==="; 198 174 handle_connection( this.conn, p.out.fd, buffer, len, &p.f, last ); 175 176 if( options.log ) mutex(sout) sout | "=== Connection closed ==="; 199 177 if(this.done) break; 200 this.conn.stats.sendfile.maxfd = max(this.conn.stats.sendfile.maxfd, p.out.fd); 201 this.conn.stats.sendfile.close++; 202 203 if( options.log ) mutex(sout) sout | "=== Connection closed ==="; 204 } 205 206 lock(stats_thrd->stats.lock __cfaabi_dbg_ctx2); 207 push(this.conn.stats.sendfile, stats_thrd->stats.send); 208 unlock(stats_thrd->stats.lock); 178 } 209 179 } 210 180 … … 228 198 229 199 static inline void push_connection( Acceptor & this, int fd ) { 230 this.stats.accepts++;231 200 PendingRead * p = 0p; 232 201 for() { … … 234 203 p = pop(*this.queue); 235 204 if(p) break; 236 // abort( "Too few threads" );237 205 yield(); 238 206 this.stats.creates++; … … 244 212 245 213 // #define ACCEPT_SPIN 246 #define ACCEPT_ONE 247 // #define ACCEPT_MANY 214 #define ACCEPT_MANY 248 215 249 216 void main( Acceptor & this ) { … … 265 232 abort( "accept error: (%d) %s\n", (int)errno, strerror(errno) ); 266 233 } 234 this.stats.accepts++; 267 235 268 236 if(this.done) return; … … 274 242 if (stats_thrd) { 275 243 unsigned long long next = rdtscl(); 276 if(next > (last + period)) {244 if(next > (last + 500000000)) { 277 245 if(try_lock(stats_thrd->stats.lock)) { 278 246 push(this.stats, stats_thrd->stats.accpt); … … 281 249 } 282 250 } 283 }284 285 if( options.log ) sout | "=== Accepting connection ===";286 }287 288 #elif defined(ACCEPT_ONE)289 if( options.log ) sout | "=== Accepting connection ===";290 for() {291 int fd = cfa_accept4(this.sockfd, this.[addr, addrlen, flags], 0);292 if(fd < 0) {293 if( errno == ECONNABORTED ) break;294 if( this.done && (errno == EINVAL || errno == EBADF) ) break;295 abort( "accept error: (%d) %s\n", (int)errno, strerror(errno) );296 }297 298 if(this.done) return;299 300 if( options.log ) sout | "=== New connection" | fd | "" | ", waiting for requests ===";301 302 if(fd) push_connection(this, fd);303 304 if (stats_thrd) {305 // unsigned long long next = rdtscl();306 // if(next > (last + period)) {307 if(try_lock(stats_thrd->stats.lock)) {308 push(this.stats, stats_thrd->stats.accpt);309 unlock(stats_thrd->stats.lock);310 // last = next;311 }312 // }313 251 } 314 252 … … 331 269 if (stats_thrd) { 332 270 unsigned long long next = rdtscl(); 333 if(next > (last + period)) {271 if(next > (last + 500000000)) { 334 272 if(try_lock(stats_thrd->stats.lock __cfaabi_dbg_ctx2)) { 335 273 push(this.stats, stats_thrd->stats.accpt); … … 346 284 int fd = get_res(res); 347 285 reset(res); 286 this.stats.accepts++; 348 287 if(fd < 0) { 349 288 if( errno == ECONNABORTED ) continue; … … 380 319 #error no accept algorithm specified 381 320 #endif 382 lock(stats_thrd->stats.lock); 383 push(this.stats, stats_thrd->stats.accpt); 384 unlock(stats_thrd->stats.lock); 385 } 321 }
Note:
See TracChangeset
for help on using the changeset viewer.