Changeset 8c43d05
- Timestamp:
- Jan 15, 2021, 2:26:35 PM (4 years ago)
- Branches:
- ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast-unique-expr, pthread-emulation, qualifiedEnum
- Children:
- b7664a03
- Parents:
- 804c0ff
- Location:
- benchmark/io/http
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
benchmark/io/http/filecache.cfa
r804c0ff r8c43d05 4 4 #include <string.h> 5 5 6 #include <fstream.hfa> 6 7 #include <stdlib.hfa> 7 8 … … 182 183 conflicts += put_file( raw[i], fd ); 183 184 } 184 printf("Filled cache from path \"%s\" with %zu files\n", path, fcount);185 sout | "Filled cache from path \"" | path | "\" with" | fcount | "files"; 185 186 if( conflicts > 0 ) { 186 printf("Found %d conflicts (seed: %u)\n", conflicts, options.file_cache.hash_seed);187 sout | "Found" | conflicts | "conflicts (seed: " | options.file_cache.hash_seed | ")"; 187 188 #if defined(REJECT_CONFLICTS) 188 189 abort("Conflicts found in the cache"); … … 191 192 192 193 if(options.file_cache.list) { 193 printf("Listing files and exiting\n");194 sout | "Listing files and exiting"; 194 195 for(i; fcount) { 195 196 int s; char u; 196 197 [s, u] = human_size(raw[i].size); 197 printf("%4d%c - %s\n", s, u, raw[i].file);198 sout | s | u | "-" | raw[i].file; 198 199 free(raw[i].file); 199 200 } -
benchmark/io/http/main.cfa
r804c0ff r8c43d05 10 10 } 11 11 12 #include <fstream.hfa> 12 13 #include <kernel.hfa> 13 14 #include <iofwd.hfa> … … 83 84 //=================== 84 85 // Open Files 85 printf("Filling cache from %s\n", path);86 sout | "Filling cache from" | path; 86 87 fill_cache( path ); 87 88 88 89 //=================== 89 90 // Open Socket 90 printf("%ld : Listening on port %d\n", getpid(), options.socket.port);91 sout | getpid() | ": Listening on port" | options.socket.port; 91 92 int server_fd = socket(AF_INET, SOCK_STREAM, 0); 92 93 if(server_fd < 0) { … … 108 109 if(errno == EADDRINUSE) { 109 110 if(waited == 0) { 110 printf("Waiting for port\n");111 sout | "Waiting for port"; 111 112 } else { 112 printf("\r%d", waited);113 f flush(stdout);113 sout | "\r" | waited | nonl; 114 flush( sout ); 114 115 } 115 116 waited ++; … … 173 174 unpark( workers[i] ); 174 175 } 175 printf("%d workers started on %d processors\n", options.clopts.nworkers, options.clopts.nprocs);176 sout | options.clopts.nworkers | "workers started on" | options.clopts.nprocs | "processors"; 176 177 { 177 178 char buffer[128]; … … 180 181 } 181 182 182 printf("Shutting Down\n"); 183 } 184 183 sout | "Shutdown received"; 184 } 185 186 sout | "Notifying connections"; 185 187 for(i; options.clopts.nworkers) { 186 188 workers[i].done = true; … … 188 190 } 189 191 190 printf("Shutting down socket\n");192 sout | "Shutting down socket"; 191 193 int ret = shutdown( server_fd, SHUT_RD ); 192 194 if( ret < 0 ) { abort( "shutdown error: (%d) %s\n", (int)errno, strerror(errno) ); } … … 194 196 //=================== 195 197 // Close Socket 196 printf("Closing Socket\n");198 sout | "Closing Socket"; 197 199 ret = close( server_fd ); 198 200 if(ret < 0) { 199 201 abort( "close socket error: (%d) %s\n", (int)errno, strerror(errno) ); 200 202 } 203 sout | "Stopping connection threads..." | nonl; 201 204 } 202 printf("Workers Closed\n"); 203 205 sout | "done"; 206 207 sout | "Stopping protocol threads..." | nonl; 204 208 deinit_protocol(); 205 } 206 209 sout | "done"; 210 211 sout | "Stopping processors..." | nonl; 212 } 213 sout | "done"; 214 215 sout | "Closing splice fds..." | nonl; 207 216 for(i; pipe_cnt) { 208 217 ret = close( fds[pipe_off + i] ); … … 212 221 } 213 222 free(fds); 214 215 } 223 sout | "done"; 224 225 sout | "Stopping processors..." | nonl; 226 } 227 sout | "done"; 216 228 217 229 //=================== 218 230 // Close Files 219 printf("Closing Files\n");231 sout | "Closing open files..." | nonl; 220 232 close_cache(); 221 } 233 sout | "done"; 234 } -
benchmark/io/http/protocol.cfa
r804c0ff r8c43d05 5 5 #include <fcntl.h> 6 6 } 7 8 #include <fstream.hfa> 7 9 #include <iofwd.hfa> 8 10 … … 11 13 extern "C" { 12 14 int snprintf ( char * s, size_t n, const char * format, ... ); 13 #include <linux/io_uring.h>15 // #include <linux/io_uring.h> 14 16 } 15 17 #include <string.h> … … 115 117 } 116 118 117 if( options.log ) printf("%.*s\n", rlen, buffer); 119 if( options.log ) { 120 write(sout, buffer, rlen); 121 sout | nl; 122 } 118 123 119 124 it = buffer; -
benchmark/io/http/worker.cfa
r804c0ff r8c43d05 6 6 #include <unistd.h> 7 7 8 #include <fstream.hfa> 8 9 #include <iofwd.hfa> 9 10 … … 33 34 CONNECTION: 34 35 for() { 35 if( options.log ) printf("=== Accepting connection ===\n");36 if( options.log ) sout | "=== Accepting connection ==="; 36 37 int fd = cfa_accept4( this.[sockfd, addr, addrlen, flags], 0, -1`s, &this.cancel, 0p ); 37 38 // int fd = accept4( this.[sockfd, addr, addrlen, flags] ); … … 42 43 } 43 44 44 if( options.log ) printf("=== New connection %d, waiting for requests ===\n", fd);45 if( options.log ) sout | "=== New connection" | fd | "" | ", waiting for requests ==="; 45 46 REQUEST: 46 47 for() { … … 53 54 size_t len = options.socket.buflen; 54 55 char buffer[len]; 55 if( options.log ) printf("=== Reading request ===\n");56 if( options.log ) sout | "=== Reading request ==="; 56 57 [code, closed, file, name_size] = http_read(fd, buffer, len, &this.cancel); 57 58 … … 61 62 // If this wasn't a request retrun 400 62 63 if( code != OK200 ) { 63 printf("=== Invalid Request : %d ===\n", code_val(code));64 sout | "=== Invalid Request :" | code_val(code) | "==="; 64 65 answer_error(fd, code); 65 66 continue REQUEST; … … 67 68 68 69 if(0 == strncmp(file, "plaintext", min(name_size, sizeof("plaintext") ))) { 69 if( options.log ) printf("=== Request for /plaintext ===\n");70 if( options.log ) sout | "=== Request for /plaintext ==="; 70 71 71 72 char text[] = "Hello, World!\n"; … … 75 76 if( ret == -ECONNRESET ) break REQUEST; 76 77 77 if( options.log ) printf("=== Answer sent ===\n");78 if( options.log ) sout | "=== Answer sent ==="; 78 79 continue REQUEST; 79 80 } 80 81 81 82 if(0 == strncmp(file, "ping", min(name_size, sizeof("ping") ))) { 82 if( options.log ) printf("=== Request for /ping ===\n");83 if( options.log ) sout | "=== Request for /ping ==="; 83 84 84 85 // Send the header … … 86 87 if( ret == -ECONNRESET ) break REQUEST; 87 88 88 if( options.log ) printf("=== Answer sent ===\n");89 if( options.log ) sout | "=== Answer sent ==="; 89 90 continue REQUEST; 90 91 } 91 92 92 if( options.log ) printf("=== Request for file %.*s ===\n", (int)name_size, file); 93 if( options.log ) { 94 sout | "=== Request for file " | nonl; 95 write(sout, file, name_size); 96 sout | " ==="; 97 } 93 98 94 99 // Get the fd from the file cache … … 99 104 // If we can't find the file, return 404 100 105 if( ans_fd < 0 ) { 101 printf("=== File Not Found ===\n"); 106 sout | "=== File Not Found (" | nonl; 107 write(sout, file, name_size); 108 sout | ") ==="; 102 109 answer_error(fd, E404); 103 110 continue REQUEST; … … 112 119 if( ret == -ECONNRESET ) break REQUEST; 113 120 114 if( options.log ) printf("=== Answer sent ===\n");121 if( options.log ) sout | "=== Answer sent ==="; 115 122 } 116 123 117 if( options.log ) printf("=== Connection closed ===\n");124 if( options.log ) sout | "=== Connection closed ==="; 118 125 close(fd); 119 126 continue CONNECTION;
Note: See TracChangeset
for help on using the changeset viewer.