-// unfinished load testing utility for Citadel Server
+// Load testing utility for Citadel Server
//
// Copyright (c) 1987-2023 by the citadel.org team
//
}
-
char *random_rooms[] = {
"Load Testing Test Room One",
"Load Test 2: Electric Boogaloo",
};
int nrooms = sizeof(random_rooms) / sizeof(char *);
char *test_user = "Load Test User";
-char *test_pass = "TheTestPW";
+char test_pass[16];
+
+// These are our randomized load test operations: an even mix of changing rooms, posting messages, and deleting messages.
void perform_random_thing(int serv_sock) {
int op = random() % 3;
char buf[SIZ];
}
+// This is the main loop. We log in as the load test user, and then perform random operations until stopped.
void *loadtest(void *blah) {
char buf[SIZ];
int serv_sock;
serv_puts(serv_sock, buf);
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;
long ops = 0;
- printf("\033[%d;%dH\033[32m--------\033[0m", row, col);
+ printf("\033[%d;%dH\033[33m 0\033[0m", row, col);
fflush(stdout);
- sleep(1);
+
while(1) {
perform_random_thing(serv_sock);
- printf("\033[%d;%dH\033[33m%8ld\033[0m", row, col, ++ops);
+ printf("\033[%d;%dH\033[32m%8ld\033[0m", row, col, ++ops);
fflush(stdout);
}
}
+// Create (or replace) the account used for load testing, then create the rooms in which we will load test.
void setup_accounts(int serv_sock) {
int i;
char buf[SIZ];
// Main loop. Do things and have fun.
int main(int argc, char **argv) {
- int a;
+ int i;
int nthreads = 3;
fprintf(stderr, "\033[2J\033[H"
"\033[44m\033[33m\033[1m \033[K\033[0m\n");
// Parse command line
- while ((a = getopt(argc, argv, "h:n:")) != EOF) {
- switch (a) {
+ while ((i = getopt(argc, argv, "h:n:")) != EOF) {
+ switch (i) {
case 'h':
strncpy(ctdldir, optarg, sizeof ctdldir);
break;
exit(errno);
}
+ // Generate a random password for load test user. No one needs this password except us.
+ srand(time(NULL)+getpid());
+ for (i=0; i<sizeof(test_pass)-1; ++i) {
+ test_pass[i] = (rand() % 74) + 48;
+ }
+ test_pass[sizeof(test_pass)] = 0;
+
+ // start connecting
int serv_sock = uds_connectsock(file_citadel_admin_socket);
if (serv_sock < 0) {
fprintf(stderr, "loadtest: cannot connect to Citadel Server\n");
setup_accounts(serv_sock);
close(serv_sock);
- for (a=0; a<(nthreads-1); ++a) {
+ for (i=0; i<(nthreads-1); ++i) {
+
+ int row = 10 + ((i+1) % 20);
+ int col = ((i+1) / 20) * 10;
+ printf("\033[%d;%dH\033[31m--------\033[0m", row, col);
+ fflush(stdout);
+
pthread_t thread;
pthread_attr_t attr;
int ret = 0;
}
loadtest(NULL);
-
return(0);
}