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 <sys/time.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#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_message_callback(struct mosquitto *mosq, void *obj, const struct mosquitto_message *msg)
|
|
|
|
{
|
|
|
|
message_count++;
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
|
|
|
struct mosquitto *mosq;
|
2020-10-07 16:20:50 +00:00
|
|
|
int c;
|
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_message_callback_set(mosq, my_message_callback);
|
|
|
|
|
2018-05-02 13:03:26 +00:00
|
|
|
mosquitto_connect(mosq, HOST, PORT, 600);
|
2020-10-07 16:20:50 +00:00
|
|
|
mosquitto_subscribe(mosq, NULL, "perf/test", SUB_QOS);
|
2014-05-07 22:27:00 +00:00
|
|
|
|
2020-10-07 16:20:50 +00:00
|
|
|
mosquitto_loop_start(mosq);
|
|
|
|
while(1){
|
|
|
|
sleep(1);
|
|
|
|
c = message_count;
|
|
|
|
message_count = 0;
|
|
|
|
printf("%d\n", c);
|
2014-05-07 22:27:00 +00:00
|
|
|
|
2020-10-07 16:20:50 +00:00
|
|
|
}
|
2014-05-07 22:27:00 +00:00
|
|
|
|
|
|
|
mosquitto_destroy(mosq);
|
|
|
|
mosquitto_lib_cleanup();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|