• # C

    Posté par (site web personnel) . En réponse au journal Le TapTempo du web, mais plus rapide. Évalué à 4.

    Avec libmicrohttpd (installé depuis un package debian sur Ubuntu 20.04):

    Avec ./wrk -d10s -t4:

    Requests/sec: 217045.72
    Transfer/sec: 31.69MB
    Code:

    #include <stdio.h>
    #include <string.h>
    #include <stdlib.h>
    #include <time.h>
    #include <unistd.h>
    #include <microhttpd.h>
    static int avatar_location(void * cls, struct MHD_Connection * connection,
     const char * url, const char * method,
     const char * version, const char * upload_data,
     size_t * upload_data_size, void ** ptr) {
     struct MHD_Response * response;
     char location[] = "https://avatar.spacefox.fr/Renard-XXXX.png";
     int ret;
     if (0 != strcmp(method, "GET"))
     return MHD_NO; /* unexpected method */
     response = MHD_create_response_from_buffer(0, NULL, MHD_RESPMEM_PERSISTENT);
     snprintf(&location[34], sizeof(location)-34, "%d.png", rand() % 11);
     MHD_add_response_header(response, "Location", location);
     ret = MHD_queue_response(connection, MHD_HTTP_FOUND, response);
     MHD_destroy_response(response);
     return ret;
    }
    int main(int argc, char ** argv) {
     struct MHD_Daemon * d;
     if (argc != 2) {
     printf("%s PORT\n", argv[0]);
     return 1;
     }
     srand(time(NULL));
     d = MHD_start_daemon(MHD_USE_THREAD_PER_CONNECTION, atoi(argv[1]),
     NULL, NULL, &avatar_location, NULL, MHD_OPTION_END);
     if (d == NULL)
     return 1;
     (void) getc (stdin);
     MHD_stop_daemon(d);
     return 0;
    }

    et

    gcc main.c -lmicrohttpd -O3 -o ./taptempoweb