Skip to content

Commit

Permalink
added http benchmark script
Browse files Browse the repository at this point in the history
  • Loading branch information
asiegel-jt committed Nov 8, 2024
1 parent ad535ed commit cd5ff46
Show file tree
Hide file tree
Showing 6 changed files with 214 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/app/fdctl/run/tiles/fd_repair.c
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ repair_shred_deliver_fail( fd_pubkey_t const * id FD_PARAM_UNUSED,
uint shred_index,
void * arg FD_PARAM_UNUSED,
int reason ) {
FD_LOG_WARNING(( "repair failed to get shred - slot: %lu, shred_index: %u, reason: %u", slot, shred_index, reason ));
FD_LOG_WARNING(( "repair failed to get shred - slot: %lu, shred_index: %u, reason: %d", slot, shred_index, reason ));
}

static inline int
Expand Down Expand Up @@ -566,7 +566,7 @@ unprivileged_init( fd_topo_t * topo,
if( ctx->blockstore_wksp==NULL ) {
FD_LOG_ERR(( "no blocktore workspace" ));
}

ctx->blockstore = fd_blockstore_join( fd_topo_obj_laddr( topo, blockstore_obj_id ) );
FD_TEST( ctx->blockstore!=NULL );

Expand Down
2 changes: 1 addition & 1 deletion src/app/fdctl/run/topos/fd_firedancer.c
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,7 @@ fd_topo_initialize( config_t * config ) {
FD_TEST( config->gossip.port == config->tiles.gossip.gossip_listen_port );
tile->gossip.tvu_port = config->tiles.shred.shred_listen_port;
if( FD_UNLIKELY( tile->gossip.tvu_port>(ushort)(USHORT_MAX-6) ) )
FD_LOG_ERR(( "shred_listen_port in the config must not be greater than %u", (ushort)(USHORT_MAX-6) ));
FD_LOG_ERR(( "shred_listen_port in the config must not be greater than %hu", (ushort)(USHORT_MAX-6) ));
tile->gossip.tvu_fwd_port = (ushort)(config->tiles.shred.shred_listen_port + 6);
tile->gossip.expected_shred_version = config->consensus.expected_shred_version;
tile->gossip.tpu_port = config->tiles.quic.regular_transaction_listen_port;
Expand Down
1 change: 1 addition & 0 deletions src/ballet/http/Local.mk
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ $(call make-unit-test,test_http_server,test_http_server,fd_ballet fd_util)
$(call run-unit-test,test_http_server)

$(call make-unit-test,test_live_http_server,test_live_http_server,fd_ballet fd_util)
$(call make-unit-test,test_http_bench_server,test_http_bench_server,fd_ballet fd_util)

ifdef FD_HAS_HOSTED
$(call make-fuzz-test,fuzz_picohttpparser,fuzz_picohttpparser,fd_ballet fd_util)
Expand Down
183 changes: 183 additions & 0 deletions src/ballet/http/test_http_bench_server.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,183 @@
#include "../fd_ballet.h"

#include "fd_http_server.h"

#include <malloc.h>
#include <signal.h>
#include <errno.h>
#include <stdlib.h>

static volatile int stop = 0;

static void
signal_handler( int sig ) {
(void)sig;
stop = 1;
}

static void
install_signal_handler( void ) {
struct sigaction sa = {
.sa_handler = signal_handler,
.sa_flags = 0,
};
if( FD_UNLIKELY( sigaction( SIGINT, &sa, NULL ) ) )
FD_LOG_ERR(( "sigaction(SIGINT) failed (%i-%s)", errno, fd_io_strerror( errno ) ));
}

struct test_http_server {
fd_http_server_t * http;
};

typedef struct test_http_server test_http_server_t;

#define SMALL_SIZE 8
#define BIG_SIZE (1<<18)
static uchar response_data[BIG_SIZE];

static fd_http_server_response_t
request( fd_http_server_request_t const * request ) {
test_http_server_t * state = (test_http_server_t *)request->ctx;

if( FD_LIKELY( request->method==FD_HTTP_SERVER_METHOD_GET ) ) {
if( FD_LIKELY( request->headers.upgrade_websocket ) ) {
fd_http_server_response_t response = {
.status = 200,
.upgrade_websocket = 1,
.content_type = "text/html"
};
return response;
}

if( !strcmp(request->path, "/small") ) {
fd_http_server_memcpy( state->http, response_data, SMALL_SIZE );
fd_http_server_response_t response = {
.status = 200,
.upgrade_websocket = 0,
.content_type = "text/html"
};
FD_TEST( !fd_http_server_stage_body( state->http, &response ) );
return response;
}

if( !strcmp(request->path, "/big") ) {
fd_http_server_memcpy( state->http, response_data, BIG_SIZE );
fd_http_server_response_t response = {
.status = 200,
.upgrade_websocket = 0,
.content_type = "text/html"
};
FD_TEST( !fd_http_server_stage_body( state->http, &response ) );
return response;
}

} else if( FD_LIKELY( request->method==FD_HTTP_SERVER_METHOD_POST ) ) {
if( !strcmp(request->path, "/echo") ) {
/* path "/echo" just echoes the post */
fd_http_server_memcpy( state->http, request->post.body, request->post.body_len );
fd_http_server_response_t response = {
.status = 200,
.upgrade_websocket = 0,
.content_type = "text/html"
};
FD_TEST( !fd_http_server_stage_body( state->http, &response ) );
return response;
}
}

fd_http_server_printf( state->http, "INVALID TEST POST\n" );
fd_http_server_response_t response = {
.status = 400,
.upgrade_websocket = 0,
.content_type = "text/html"
};
FD_TEST( !fd_http_server_stage_body( state->http, &response ) );
return response;
}

static void
http_close( ulong conn_id,
int reason,
void * ctx ) {
(void)conn_id;
(void)reason;
(void)ctx;
}

static void
ws_open( ulong ws_conn_id,
void * ctx ) {
(void)ws_conn_id;
(void)ctx;
}

static void
ws_close( ulong ws_conn_id,
int reason,
void * ctx ) {
(void)ws_conn_id;
(void)reason;
(void)ctx;
}

static void
ws_message( ulong ws_conn_id,
uchar const * data,
ulong data_len,
void * ctx ) {
(void)ws_conn_id;
(void)data;
(void)data_len;
(void)ctx;
}

int
main( int argc,
char ** argv ) {
fd_boot( &argc, &argv );

for( uint i=0; i < BIG_SIZE; ++i ) {
response_data[i] = (uchar)(' ' + (char)(i&63));
}
response_data[SMALL_SIZE-1] = '\n';
response_data[BIG_SIZE-1] = '\n';

fd_http_server_params_t params = {
.max_connection_cnt = 150UL,
.max_ws_connection_cnt = 2UL,
.max_request_len = 2048UL,
.max_ws_recv_frame_len = 2048UL,
.max_ws_send_frame_cnt = 100UL,
.outgoing_buffer_sz = 10*BIG_SIZE,
};

fd_http_server_callbacks_t callbacks = {
.request = request,
.close = http_close,
.ws_open = ws_open,
.ws_close = ws_close,
.ws_message = ws_message,
};

test_http_server_t state;
state.http = fd_http_server_join( fd_http_server_new( aligned_alloc( fd_http_server_align(), fd_http_server_footprint( params ) ),
params,
callbacks,
&state ) );

FD_TEST( fd_http_server_listen( state.http, 0, 4321U ) );

FD_LOG_NOTICE(( "serving http://localhost:4321" ));

install_signal_handler();

while( !stop ) {
fd_http_server_poll( state.http );
}

free( fd_http_server_delete( fd_http_server_leave( state.http ) ) );

FD_LOG_NOTICE(( "pass" ));
fd_halt();
return 0;
}
2 changes: 1 addition & 1 deletion src/ballet/http/test_live_http_server.c
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ main( int argc,
fd_http_server_params_t params = {
.max_connection_cnt = 5UL,
.max_ws_connection_cnt = 2UL,
.max_request_len = 1<<16,
.max_request_len = 2048UL,
.max_ws_recv_frame_len = 2048UL,
.max_ws_send_frame_cnt = 100UL,
.outgoing_buffer_sz = 4096UL,
Expand Down
26 changes: 26 additions & 0 deletions src/ballet/http/wrk_script.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/bash

echo "install wrk with:"
echo " git clone https://github.com/wg/wrk.git"
echo " cd wrk"
echo " make"

echo
echo "single thread, small responses"
./wrk -c 1 -d 10 -t 1 --latency http://localhost:4321/small

echo
echo "single thread, big responses"
./wrk -c 1 -d 10 -t 1 --latency http://localhost:4321/big

echo
echo "multi-threaded, small responses"
./wrk -c 30 -d 10 -t 30 --latency http://localhost:4321/small

echo
echo "super multi-threaded, small responses"
./wrk -c 100 -d 10 -t 50 --latency http://localhost:4321/small

echo
echo "multi-threaded, big responses"
./wrk -c 5 -d 10 -t 5 --latency http://localhost:4321/big

0 comments on commit cd5ff46

Please sign in to comment.