# A Distributed Real-Time Monitoring Scheme for Air Pressure Stream Data Based on Kafka
## 4 Experimental Results and Analysis
### Delay Comparison between Kafka and ActiveMQ  
We conducted tests and comparisons between Kafka and ActiveMQ to compare the transmission delay by using different messaging middleware in the scheme. We aimed to understand the time taken for information to be transmitted under different numbers of devices, thereby determining a reasonable scale for the sensor network and evaluating the performance of different messaging middleware in the scheme.  
We employed a combination of practical and simulated data to simulate the practical working environment in order to test the delay, with the aim of assessing the time required for different numbers of devices to send a message from the producer end to the consumer end via Kafka and ActiveMQ. This experiment consisted of six test groups, covering scenarios where 1000, 3000, 10,000, 30,000, 100,000, and 300,000 devices each transmitted a single message, which ensured the comprehensiveness and reliability of the test results.  
In a single transmission, the sensor devices send data containing the device ID, pressure value, battery level, and signal strength to the producer. The producer consolidates these data into a JSON format message of 40 bytes, which is ultimately consumed by the consumer. We calculated the delay of information transmission by computing the time difference between the sending and receiving of the data.  
The specific testing process is as follows. Firstly, we created producers and consumers for Kafka and recorded the time differences for each test group from when the producer sent the data to when the consumer received it. When the producer received real-time data from the sensors, the scheme integrated the real-time data with the simulated data into a data queue ready for transmission. Before sending the message, we recorded the start time. When the consumer pulled messages from the topic, the received data were processed; these data included information such as the topic, partition, offset, and data, which are encapsulated in ConsumerRecords [38]. In Kafka versions 0.9 and later, the consumer record includes a timestamp field [39]. Therefore, we defined the timestamp of the last message received by the consumer as the end time. We obtained the transmission delay by calculating the difference between the end and start times. The calculation method for ActiveMQ transmission delay is comparable to this process.  
In the transmission delay test of Kafka and ActiveMQ, we conducted 10 tests for each test group and took the average of these tests as the final test result.  
Figure 8 displays the delay comparison results between Kafka and ActiveMQ. For the six different test groups, the average delays for Kafka were 15.6 ms, 23.1 ms, 48.6 ms, 96.3 ms, 206.1 ms, and 336.1 ms, respectively; ActiveMQ's average delays were 48.9 ms, 92.5 ms, 271.9 ms, 562.8 ms, 1557.6 ms, and 4374.5 ms, respectively. ActiveMQ's delay was between 3 to 10 times that of Kafka. When the number of devices is small, the difference in delay between the two is small. However, as the number of devices increases, the difference gradually increases.  
Batch-based Kafka offers lower transmission delays compared to ActiveMQ, which is based on a message queue. Kafka can handle more simultaneous data, resulting in lower propagation delays when processing the same amount of data. This makes Kafka more suitable for real-time processing of air pressure data.