Updated crude performance test.

This commit is contained in:
Roger A. Light 2018-05-02 14:03:26 +01:00
parent 95d26bb0e6
commit d3b3ba86f1
3 changed files with 17 additions and 69 deletions

View File

@ -1,3 +1,9 @@
#define HOST "127.0.0.1"
#define PORT 1888
#define PUB_QOS 1
#define SUB_QOS 1
#define MESSAGE_COUNT 100000L #define MESSAGE_COUNT 100000L
#define MESSAGE_SIZE 1024L #define MESSAGE_SIZE 1024L

View File

@ -27,60 +27,17 @@ void my_disconnect_callback(struct mosquitto *mosq, void *obj, int result)
void my_publish_callback(struct mosquitto *mosq, void *obj, int mid) void my_publish_callback(struct mosquitto *mosq, void *obj, int mid)
{ {
message_count++; message_count++;
//printf("%d ", message_count);
if(message_count == MESSAGE_COUNT){ if(message_count == MESSAGE_COUNT){
gettimeofday(&stop, NULL); gettimeofday(&stop, NULL);
mosquitto_disconnect((struct mosquitto *)obj); mosquitto_disconnect((struct mosquitto *)obj);
} }
} }
int create_data(void)
{
int i;
FILE *fptr, *rnd;
int rc = 0;
char buf[MESSAGE_SIZE];
fptr = fopen("msgsps_pub.dat", "rb");
if(fptr){
fseek(fptr, 0, SEEK_END);
if(ftell(fptr) >= MESSAGE_SIZE*MESSAGE_COUNT){
fclose(fptr);
return 0;
}
fclose(fptr);
}
fptr = fopen("msgsps_pub.dat", "wb");
if(!fptr) return 1;
rnd = fopen("/dev/urandom", "rb");
if(!rnd){
fclose(fptr);
return 1;
}
for(i=0; i<MESSAGE_COUNT; i++){
if(fread(buf, sizeof(char), MESSAGE_SIZE, rnd) != MESSAGE_SIZE){
rc = 1;
break;
}
if(fwrite(buf, sizeof(char), MESSAGE_SIZE, fptr) != MESSAGE_SIZE){
rc = 1;
break;
}
}
fclose(rnd);
fclose(fptr);
return rc;
}
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
struct mosquitto *mosq; struct mosquitto *mosq;
int i; int i;
double dstart, dstop, diff; double dstart, dstop, diff;
FILE *fptr;
uint8_t *buf; uint8_t *buf;
buf = malloc(MESSAGE_SIZE*MESSAGE_COUNT); buf = malloc(MESSAGE_SIZE*MESSAGE_COUNT);
@ -94,18 +51,6 @@ int main(int argc, char *argv[])
stop.tv_sec = 0; stop.tv_sec = 0;
stop.tv_usec = 0; stop.tv_usec = 0;
if(create_data()){
printf("Error: Unable to create random input data.\n");
return 1;
}
fptr = fopen("msgsps_pub.dat", "rb");
if(!fptr){
printf("Error: Unable to open random input data.\n");
return 1;
}
fread(buf, sizeof(uint8_t), MESSAGE_SIZE*MESSAGE_COUNT, fptr);
fclose(fptr);
mosquitto_lib_init(); mosquitto_lib_init();
mosq = mosquitto_new("perftest", true, NULL); mosq = mosquitto_new("perftest", true, NULL);
@ -113,15 +58,16 @@ int main(int argc, char *argv[])
mosquitto_disconnect_callback_set(mosq, my_disconnect_callback); mosquitto_disconnect_callback_set(mosq, my_disconnect_callback);
mosquitto_publish_callback_set(mosq, my_publish_callback); mosquitto_publish_callback_set(mosq, my_publish_callback);
mosquitto_connect(mosq, "127.0.0.1", 1884, 600); mosquitto_connect(mosq, HOST, PORT, 600);
mosquitto_loop_start(mosq);
i=0; i=0;
while(!mosquitto_loop(mosq, 1, 10) && run){ for(i=0; i<MESSAGE_COUNT; i++){
if(i<MESSAGE_COUNT){ mosquitto_publish(mosq, NULL, "perf/test", MESSAGE_SIZE, &buf[i*MESSAGE_SIZE], PUB_QOS, false);
mosquitto_publish(mosq, NULL, "perf/test", MESSAGE_SIZE, &buf[i*MESSAGE_SIZE], 0, false);
i++;
}
} }
mosquitto_loop_stop(mosq, false);
dstart = (double)start.tv_sec*1.0e6 + (double)start.tv_usec; dstart = (double)start.tv_sec*1.0e6 + (double)start.tv_usec;
dstop = (double)stop.tv_sec*1.0e6 + (double)stop.tv_usec; dstop = (double)stop.tv_sec*1.0e6 + (double)stop.tv_usec;
diff = (dstop-dstart)/1.0e6; diff = (dstop-dstart)/1.0e6;

View File

@ -30,7 +30,7 @@ void my_message_callback(struct mosquitto *mosq, void *obj, const struct mosquit
if(message_count == 0){ if(message_count == 0){
gettimeofday(&start, NULL); gettimeofday(&start, NULL);
} }
fwrite(msg->payload, sizeof(uint8_t), msg->payloadlen, fptr); //fwrite(msg->payload, sizeof(uint8_t), msg->payloadlen, fptr);
message_count++; message_count++;
if(message_count == MESSAGE_COUNT){ if(message_count == MESSAGE_COUNT){
gettimeofday(&stop, NULL); gettimeofday(&stop, NULL);
@ -44,7 +44,6 @@ int main(int argc, char *argv[])
double dstart, dstop, diff; double dstart, dstop, diff;
int mid = 0; int mid = 0;
char id[50]; char id[50];
int rc;
start.tv_sec = 0; start.tv_sec = 0;
start.tv_usec = 0; start.tv_usec = 0;
@ -64,13 +63,10 @@ int main(int argc, char *argv[])
mosquitto_disconnect_callback_set(mosq, my_disconnect_callback); mosquitto_disconnect_callback_set(mosq, my_disconnect_callback);
mosquitto_message_callback_set(mosq, my_message_callback); mosquitto_message_callback_set(mosq, my_message_callback);
mosquitto_connect(mosq, "127.0.0.1", 1884, 600); mosquitto_connect(mosq, HOST, PORT, 600);
mosquitto_subscribe(mosq, &mid, "perf/test", 0); mosquitto_subscribe(mosq, &mid, "perf/test", SUB_QOS);
do{ mosquitto_loop_forever(mosq, 10, 1);
rc = mosquitto_loop(mosq, 1, 10);
}while(rc == MOSQ_ERR_SUCCESS && run);
printf("rc: %d\n", rc);
dstart = (double)start.tv_sec*1.0e6 + (double)start.tv_usec; dstart = (double)start.tv_sec*1.0e6 + (double)start.tv_usec;
dstop = (double)stop.tv_sec*1.0e6 + (double)stop.tv_usec; dstop = (double)stop.tv_sec*1.0e6 + (double)stop.tv_usec;