Changeset 481ee28 for benchmark/io/http


Ignore:
Timestamp:
Jan 12, 2021, 1:12:24 PM (3 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
7dafb7b
Parents:
35285fd
Message:

Removed experiment type, server just supports both urls.
Logging is now optional.
Added done flag so spurious invalid accepts are caught.

Location:
benchmark/io/http
Files:
6 edited

Legend:

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

    r35285fd r481ee28  
    5959        //===================
    6060        // Open Files
    61         if (FileExperiment == options.experiment.type) {
    62                 printf("Filling cache from %s\n", path);
    63                 fill_cache( path );
    64         }
     61        printf("Filling cache from %s\n", path);
     62        fill_cache( path );
    6563
    6664        //===================
     
    162160                                for(i; options.clopts.nworkers) {
    163161                                        printf("Cancelling %p\n", (void*)workers[i].cancel.target);
     162                                        workers[i].done = true;
    164163                                        cancel(workers[i].cancel);
    165164                                }
  • benchmark/io/http/options.cfa

    r35285fd r481ee28  
    1515
    1616Options options @= {
    17         { // experiment
    18                 FileExperiment, // type
    19         },
     17        false, // log
    2018
    2119        { // file_cache
     
    4341};
    4442
    45 static bool parse(const char * arg, ExprimentType & value) {
    46         if(strcmp(arg, "file") == 0) {
    47                 value = FileExperiment;
    48                 return true;
    49         }
    50 
    51         if(strcmp(arg, "plaintext") == 0) {
    52                 value = HelloWorldExperiment;
    53                 return true;
    54         }
    55 
    56         return false;
    57 }
    58 
    5943const char * parse_options( int argc, char * argv[] ) {
    6044        bool subthrd = false;
     
    6852                {'p', "port",           "Port the server will listen on", options.socket.port},
    6953                {'c', "cpus",           "Number of processors to use", options.clopts.nprocs},
    70                 {'T', "experiment",     "Experiment type to run: file, plaintext", options.experiment.type},
     54                {'L', "log",            "Enable logs", options.log, parse_settrue},
    7155                {'t', "threads",        "Number of worker threads to use", options.clopts.nworkers},
    7256                {'b', "accept-backlog", "Maximum number of pending accepts", options.socket.backlog},
  • benchmark/io/http/options.hfa

    r35285fd r481ee28  
    77struct cluster;
    88
    9 enum ExprimentType {
    10         FileExperiment,
    11         HelloWorldExperiment
    12 };
    13 
    149struct Options {
    15         struct {
    16                 ExprimentType type;
    17         } experiment;
     10        bool log;
    1811
    1912        struct {
  • benchmark/io/http/protocol.cfa

    r35285fd r481ee28  
    103103        }
    104104
    105         printf("%.*s\n", rlen, buffer);
     105        if( options.log ) printf("%.*s\n", rlen, buffer);
    106106
    107107        it = buffer;
  • benchmark/io/http/worker.cfa

    r35285fd r481ee28  
    1919        this.pipe[0] = -1;
    2020        this.pipe[1] = -1;
     21        this.done = false;
     22}
     23
     24extern "C" {
     25extern int accept4(int sockfd, struct sockaddr *addr, socklen_t *addrlen, int flags);
    2126}
    2227
     
    2833        CONNECTION:
    2934        for() {
    30                 printf("=== Accepting connection ===\n");
     35                if( options.log ) printf("=== Accepting connection ===\n");
    3136                int fd = cfa_accept4( this.[sockfd, addr, addrlen, flags], 0, -1`s, &this.cancel, 0p );
     37                // int fd = accept4( this.[sockfd, addr, addrlen, flags] );
    3238                if(fd < 0) {
    3339                        if( errno == ECONNABORTED ) break;
    34                         if( errno == EINVAL ) break;
     40                        if( errno == EINVAL && this.done ) break;
    3541                        abort( "accept error: (%d) %s\n", (int)errno, strerror(errno) );
    3642                }
    3743
    38                 printf("=== New connection %d, waiting for requests ===\n", fd);
     44                if( options.log ) printf("=== New connection %d, waiting for requests ===\n", fd);
    3945                REQUEST:
    4046                for() {
     
    4753                        size_t len = options.socket.buflen;
    4854                        char buffer[len];
    49                         printf("=== Reading request ===\n");
     55                        if( options.log ) printf("=== Reading request ===\n");
    5056                        [code, closed, file, name_size] = http_read(fd, buffer, len, &this.cancel);
    5157
    5258                        // if we are done, break out of the loop
    5359                        if( closed ) {
    54                                 printf("=== Connection closed ===\n");
     60                                if( options.log ) printf("=== Connection closed ===\n");
    5561                                continue CONNECTION;
    5662                        }
     
    5864                        // If this wasn't a request retrun 400
    5965                        if( code != OK200 ) {
    60                                 printf("=== Invalid Request : %d ===\n", code_val(code));
     66                                if( options.log ) printf("=== Invalid Request : %d ===\n", code_val(code));
    6167                                answer_error(fd, code);
    6268                                continue REQUEST;
     
    6470
    6571                        if(0 == strncmp(file, "plaintext", min(name_size, sizeof("plaintext") ))) {
    66                                 printf("=== Request for /plaintext ===\n");
     72                                if( options.log ) printf("=== Request for /plaintext ===\n");
    6773
    6874                                char text[] = "Hello, World!\n";
     
    7278                        }
    7379                        else {
    74                                 printf("=== Request for file %.*s ===\n", (int)name_size, file);
     80                                if( options.log ) printf("=== Request for file %.*s ===\n", (int)name_size, file);
    7581
    7682                                // Get the fd from the file cache
     
    8187                                // If we can't find the file, return 404
    8288                                if( ans_fd < 0 ) {
    83                                         printf("=== File Not Found ===\n");
     89                                        if( options.log ) printf("=== File Not Found ===\n");
    8490                                        answer_error(fd, E404);
    8591                                        continue REQUEST;
     
    9399                        }
    94100
    95                         printf("=== Answer sent ===\n");
     101                        if( options.log ) printf("=== Answer sent ===\n");
    96102                }
    97103        }
  • benchmark/io/http/worker.hfa

    r35285fd r481ee28  
    1818        int flags;
    1919        io_cancellation cancel;
     20        volatile bool done;
    2021};
    2122void ?{}( Worker & this);
Note: See TracChangeset for help on using the changeset viewer.