X-Git-Url: https://code.citadel.org/?a=blobdiff_plain;f=citadel%2Futils%2Floadtest.c;h=6ed6e979f453cfcbcce035da77adb18851e00ce3;hb=51c0c7fe81708028e1191bd6149c30707cd4c541;hp=67a8209749b2ff646d36ea05695573d635ab00df;hpb=b14f41e653d93296e79dff298998966bb98769e5;p=citadel.git diff --git a/citadel/utils/loadtest.c b/citadel/utils/loadtest.c index 67a820974..6ed6e979f 100644 --- a/citadel/utils/loadtest.c +++ b/citadel/utils/loadtest.c @@ -1,6 +1,6 @@ // Load testing utility for Citadel Server // -// Copyright (c) 1987-2023 by the citadel.org team +// Copyright (c) 1987-2024 by the citadel.org team // // This program is open source software. Use, duplication, or disclosure // is subject to the terms of the GNU General Public License, version 3. @@ -208,6 +208,8 @@ char *random_rooms[] = { int nrooms = sizeof(random_rooms) / sizeof(char *); char *test_user = "Load Test User"; char test_pass[16]; +time_t time_started; +volatile int ops_completed; // These are our randomized load test operations: an even mix of changing rooms, posting messages, and deleting messages. @@ -270,15 +272,17 @@ void perform_random_thing(int serv_sock) { serv_gets(serv_sock, buf); } while ( (buf[0] != '2') && (total_msgs > 0)); } - } +#define ROW_OFFSET 8 // This is the main loop. We log in as the load test user, and then perform random operations until stopped. -void *loadtest(void *blah) { +void *loadtest(void *pointer_to_thread_id) { char buf[SIZ]; int serv_sock; + int thread_id = *(int *)pointer_to_thread_id; + serv_sock = uds_connectsock(file_citadel_socket); if (serv_sock < 0) { @@ -299,8 +303,8 @@ void *loadtest(void *blah) { serv_gets(serv_sock, buf); // Find a nice spot on the screen to show the operation count for this thread. - int row = 10 + ((serv_sock-3) % 20); - int col = ((serv_sock-3) / 20) * 10; + int row = ROW_OFFSET + (thread_id % 20); + int col = (thread_id / 20) * 10; long ops = 0; printf("\033[%d;%dH\033[33m 0\033[0m", row, col); fflush(stdout); @@ -308,6 +312,10 @@ void *loadtest(void *blah) { while(1) { perform_random_thing(serv_sock); printf("\033[%d;%dH\033[32m%8ld\033[0m", row, col, ++ops); + ++ops_completed; // this is declared "volatile" so we don't need to lock it + if (thread_id == 0) { + printf("\033[2;55H\033[44m\033[33m\033[1m%d ops/sec \033[0m", (ops_completed / (time(NULL) - time_started))); + } fflush(stdout); } } @@ -342,15 +350,17 @@ void setup_accounts(int serv_sock) { // Main loop. Do things and have fun. int main(int argc, char **argv) { int i; - int nthreads = 3; - - fprintf(stderr, "\033[2J\033[H" - "\033[44m\033[33m\033[1m \033[K\033[0m\n" - "\033[44m\033[33m\033[1m Load testing utility for Citadel \033[K\033[0m\n" - "\033[44m\033[33m\033[1m Copyright (c) 2023 by citadel.org et al. \033[K\033[0m\n" - "\033[44m\033[33m\033[1m This program is open source software. Use, duplication, or disclosure \033[K\033[0m\n" - "\033[44m\033[33m\033[1m is subject to the terms of the GNU General Public license v3. \033[K\033[0m\n" - "\033[44m\033[33m\033[1m \033[K\033[0m\n"); + int nthreads = 10; + int row, col; + + fprintf(stderr, "\033[2J\033[H\033[44m\033[1m" + "╔════════════════════════════════════════════════════════════════════════╗\n" + "║ Load testing utility for Citadel ║\n" + "║ Copyright (c) 2023-2024 by citadel.org et al. ║\n" + "║ This program is open source software. Use, duplication, or disclosure ║\n" + "║ is subject to the terms of the GNU General Public license v3. ║\n" + "╚════════════════════════════════════════════════════════════════════════╝\033[0m\n" + ); // Parse command line while ((i = getopt(argc, argv, "h:n:")) != EOF) { @@ -379,6 +389,14 @@ int main(int argc, char **argv) { } test_pass[sizeof(test_pass)] = 0; + // paint the screen + for (i=0; i