2014-05-07 22:27:00 +00:00
|
|
|
/* This provides a crude manner of testing the performance of a broker in messages/s. */
|
|
|
|
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2020-10-07 16:20:50 +00:00
|
|
|
#include <unistd.h>
|
2014-05-07 22:27:00 +00:00
|
|
|
#include <mosquitto.h>
|
2020-10-07 20:19:53 +00:00
|
|
|
#include <stdatomic.h>
|
2014-05-07 22:27:00 +00:00
|
|
|
|
|
|
|
#include <msgsps_common.h>
|
|
|
|
|
2020-10-07 20:19:53 +00:00
|
|
|
static atomic_int message_count = 0;
|
2014-05-07 22:27:00 +00:00
|
|
|
|
|
|
|
void my_publish_callback(struct mosquitto *mosq, void *obj, int mid)
|
|
|
|
{
|
|
|
|
message_count++;
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
|
|
|
struct mosquitto *mosq;
|
|
|
|
int i;
|
2020-10-07 16:20:50 +00:00
|
|
|
uint8_t buf[MESSAGE_SIZE];
|
2021-10-05 14:20:37 +00:00
|
|
|
|
2014-05-07 22:27:00 +00:00
|
|
|
mosquitto_lib_init();
|
|
|
|
|
2020-10-07 16:20:50 +00:00
|
|
|
mosq = mosquitto_new(NULL, true, NULL);
|
2014-05-07 22:27:00 +00:00
|
|
|
mosquitto_publish_callback_set(mosq, my_publish_callback);
|
2018-05-02 13:03:26 +00:00
|
|
|
mosquitto_connect(mosq, HOST, PORT, 600);
|
|
|
|
mosquitto_loop_start(mosq);
|
2014-05-07 22:27:00 +00:00
|
|
|
|
|
|
|
i=0;
|
2020-10-07 16:20:50 +00:00
|
|
|
while(1){
|
|
|
|
mosquitto_publish(mosq, NULL, "perf/test", sizeof(buf), buf, PUB_QOS, false);
|
|
|
|
usleep(100);
|
|
|
|
i++;
|
|
|
|
if(i == 10000){
|
|
|
|
/* Crude "messages per second" count */
|
|
|
|
i = message_count;
|
|
|
|
message_count = 0;
|
|
|
|
printf("%d\n", i);
|
|
|
|
i = 0;
|
|
|
|
}
|
2014-05-07 22:27:00 +00:00
|
|
|
}
|
2018-05-02 13:03:26 +00:00
|
|
|
mosquitto_loop_stop(mosq, false);
|
2014-05-07 22:27:00 +00:00
|
|
|
mosquitto_destroy(mosq);
|
|
|
|
mosquitto_lib_cleanup();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|