34000 requests per second on a modest laptop


This example shows how to create and start an application server, and how to connect to it and make requests from a C client (or from any language that supports C API extension). Create new directory for the RimStone server and also for C API client:
mkdir -p srv-example
cd srv-example
mkdir -p client

File "srv.rim" will have the code:
cat << 'EOF' > srv.rim
begin-handler /srv public
    silent-header
    @Hello world!
end-handler
EOF

Create RimStone application server:
rim -k hello

Build RimStone application server (exclude client directory as it contains C API client). We use --release for a production executable of high performance:
rim -q --exclude-dir=client --release

Start the application server (a single-process server in this case):
mrim -w 1 hello

Next, go to C API client directory:
cd client

C file "cli.c" is created here:
cat << 'EOF' > cli.c
#include "rcli.h"

int golf_client (rim_cli *req, char *connection, char *method, char *app_path, char *request, char *url_params);

int golf_client (rim_cli *req, char *connection, char *method, char *app_path, char *request, char *url_params)
{
    memset ((char*)req, 0, sizeof(rim_cli));
    req->server = connection;
    req->req_method = method;
    req->app_path = app_path;
    req->req = request;
    req->url_params = url_params;
    return rim_cli_request (req);
}

void main ()
{
    int i;
    char dir[RIM_MAX_OS_UDIR_LEN];
    rim_dir (RIM_DIR_SOCKFILE, dir, sizeof(dir), "hello", NULL);
    for (i = 0; i < 100000; i++)
    {
        rim_cli req;
        int res = golf_client (&req, dir, "GET", "/hello", "/srv", "/");
        if (res != RIM_OKAY) printf("Request failed [%d] [%s]\n", res, req.errm);
        else printf("%s", rim_cli_data(&req));
        rim_cli_delete(&req);
    }
}
EOF

Compile the client:
gcc -o cli cli.c $(rim -i) -O3

Run it:
./cli

The result is "Hello world!" 100,000 times from each request invocation.


Copyright (c) 2019-2025 Gliim LLC. All contents on this web site is "AS IS" without warranties or guarantees of any kind.