Changeset 2cd784a


Ignore:
Timestamp:
Mar 2, 2021, 1:59:38 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:
d5006b1
Parents:
dddb3dd0
Message:

update http server according to last push

Location:
benchmark/io/http
Files:
5 edited

Legend:

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

    rdddb3dd0 r2cd784a  
    3838}
    3939
     40void ^?{}( StatsPrinter & mutex this ) {}
     41
    4042void main(StatsPrinter & this) {
    4143        LOOP: for() {
     
    5456// Globals
    5557//=============================================================================================
    56 // struct ServerProc {
    57 //      processor self;
    58 // };
    59 
    60 // void ?{}( ServerProc & this ) {
    61 //      /* paranoid */ assert( options.clopts.instance != 0p );
    62 //      (this.self){ "Benchmark Processor", *options.clopts.instance };
    63 
    64 //      #if !defined(__CFA_NO_STATISTICS__)
    65 //              if( options.clopts.procstats ) {
    66 //                      print_stats_at_exit( this.self, options.clopts.instance->print_stats );
    67 //              }
    68 //              if( options.clopts.viewhalts ) {
    69 //                      print_halts( this.self );
    70 //              }
    71 //      #endif
    72 // }
    73 
    74 // struct ServerIoContext {
    75 //      io_context self;
    76 // };
    77 
    78 // void ?{}( ServerIoContext & this ) {
    79 //      /* paranoid */ assert( options.clopts.instance != 0p );
    80 //      (this.self){ *options.clopts.instance };
    81 // }
    82 
    8358struct ServerCluster {
    8459        cluster self;
    8560        processor    * procs;
    86         io_context   * ctxs;
     61        // io_context   * ctxs;
    8762        StatsPrinter * prnt;
    8863
     
    10681        }
    10782
    108         this.ctxs = alloc(options.clopts.nprocs);
    109         for(i; options.clopts.nprocs) {
    110                 (this.ctxs[i]){ this.self };
    111         }
    112 
    113         this.prnt = alloc(options.clopts.nprocs);
    114         for(i; options.clopts.nprocs) {
    115                 (this.prnt[i]){ this.self };
     83        if(options.stats) {
     84                this.prnt = alloc();
     85                (*this.prnt){ this.self };
     86        } else {
     87                this.prnt = 0p;
    11688        }
    11789
     
    12597
    12698void ^?{}( ServerCluster & this ) {
    127         for(i; options.clopts.nprocs) {
    128                 ^(this.prnt[i]){};
    129         }
    130         free(this.prnt);
    131 
    132         for(i; options.clopts.nprocs) {
    133                 ^(this.ctxs[i]){};
    134         }
    135         free(this.ctxs);
     99        delete(this.prnt);
    136100
    137101        for(i; options.clopts.nprocs) {
     
    250214                                {
    251215                                        char buffer[128];
    252                                         while(int ret = cfa_read(0, buffer, 128, 0); ret != 0) {
     216                                        for() {
     217                                                int ret = cfa_read(0, buffer, 128, 0);
     218                                                if(ret == 0) break;
    253219                                                if(ret < 0) abort( "main read error: (%d) %s\n", (int)errno, strerror(errno) );
     220                                                sout | "User wrote '" | "" | nonl;
     221                                                write(sout, buffer, ret - 1);
     222                                                sout | "'";
    254223                                        }
    255224
  • benchmark/io/http/options.cfa

    rdddb3dd0 r2cd784a  
    2020Options options @= {
    2121        false, // log
     22        false, // stats
    2223
    2324        { // file_cache
     
    6162                {'\0', "isolate",        "Create one cluster per processor", isolate, parse_settrue},
    6263                {'\0', "log",            "Enable logs", options.log, parse_settrue},
     64                {'\0', "stats",          "Enable statistics", options.stats, parse_settrue},
    6365                {'\0', "accept-backlog", "Maximum number of pending accepts", options.socket.backlog},
    6466                {'\0', "request_len",    "Maximum number of bytes in the http request, requests with more data will be answered with Http Code 414", options.socket.buflen},
  • benchmark/io/http/options.hfa

    rdddb3dd0 r2cd784a  
    99struct Options {
    1010        bool log;
     11        bool stats;
    1112
    1213        struct {
  • benchmark/io/http/protocol.cfa

    rdddb3dd0 r2cd784a  
    5252        while(len > 0) {
    5353                // Call write
    54                 int ret = cfa_send(fd, it, len, 0, 0);
     54                int ret = cfa_send(fd, it, len, 0, CFA_IO_LAZY);
    5555                if( ret < 0 ) {
    5656                        if( errno == ECONNRESET || errno == EPIPE ) return -ECONNRESET;
     
    121121        READ:
    122122        for() {
    123                 int ret = cfa_recv(fd, (void*)it, count, 0, 0);
     123                int ret = cfa_recv(fd, (void*)it, count, 0, CFA_IO_LAZY);
    124124                // int ret = read(fd, (void*)it, count);
    125125                if(ret == 0 ) return [OK200, true, 0, 0];
     
    160160        ssize_t ret;
    161161        SPLICE1: while(count > 0) {
    162                 ret = cfa_splice(ans_fd, &offset, pipe[1], 0p, count, sflags, 0);
    163                 // ret = splice(ans_fd, &offset, pipe[1], 0p, count, sflags);
     162                ret = cfa_splice(ans_fd, &offset, pipe[1], 0p, count, sflags, CFA_IO_LAZY);
    164163                if( ret < 0 ) {
    165164                        if( errno != EAGAIN && errno != EWOULDBLOCK) continue SPLICE1;
     
    173172                size_t in_pipe = ret;
    174173                SPLICE2: while(in_pipe > 0) {
    175                         ret = cfa_splice(pipe[0], 0p, fd, 0p, in_pipe, sflags, 0);
    176                         // ret = splice(pipe[0], 0p, fd, 0p, in_pipe, sflags);
     174                        ret = cfa_splice(pipe[0], 0p, fd, 0p, in_pipe, sflags, CFA_IO_LAZY);
    177175                        if( ret < 0 ) {
    178176                                if( errno != EAGAIN && errno != EWOULDBLOCK) continue SPLICE2;
     
    232230                Time now = getTimeNsec();
    233231                strftime( buff, 100, "%a, %d %b %Y %H:%M:%S %Z", now );
     232                sout | "Updated date to '" | buff | "'";
    234233
    235234                for(i; KNOWN_CODES) {
     
    244243                this.idx = (this.idx + 1) % 2;
    245244
     245                sout | "Date thread sleeping";
     246
    246247                sleep(1`s);
    247248        }
  • benchmark/io/http/worker.cfa

    rdddb3dd0 r2cd784a  
    3737        for() {
    3838                if( options.log ) sout | "=== Accepting connection ===";
    39                 int fd = cfa_accept4( this.[sockfd, addr, addrlen, flags], 0 );
     39                int fd = cfa_accept4( this.[sockfd, addr, addrlen, flags], CFA_IO_LAZY );
    4040                if(fd < 0) {
    4141                        if( errno == ECONNABORTED ) break;
Note: See TracChangeset for help on using the changeset viewer.