After my last post about using HL7v2 in JSON I received some feedback from my colleagues that asked about performance: what is the overhead of parsing such a large message in JSON compared to a the same message in ER7.
Messages
For this benchmark I’m using a OMP^O09 message that has the following segments has “header”: MSH, NTE, PID; then 2 medications entries using two of each of the following segments: ORC, TQ1, RXO, NTE and RXR.
Size
To compare sizes, the same message was transformed to JSON format following the method described on the previous post. Some numbers about the sizes of each message:
|Characters (with spaces)|Size (bytes)|
ER7 | 1272 | 1279 |
JSON | 3323 | 3330 |
As one can see, the message represented in ER7 is 40% the size of the same message in JSON. But, is this really meaningful? 3.3 kb vs 1.3 kb? On todays reality? Think not… Let’s see if the use of JSON has impact on performance.
Performance
To measure the performance impact of this change to JSON, I used Mirth Connect, an open-source HL7 interface engine, widely used and my favorite too. The first scenario is how Mirth Connect behaves when parsing ER7 and JSON to obtain the Given Name of a Patient => PID.5.2. The same message is sent to two Channels, one for ER7 and the other for JSON. The ER7 one receives the message and then Mirth uses it’s internal parser, that transforms the ER7 into a XML and then extracts the data and prints the given name to the console. The JSON one receives the message as raw data and parses it using the JSON.parse() method. After obtaining a Javascript object, the patient’s given name is printed to the console. To measure the impact of using raw data or HL7v2 XML data internaly in Mirth Connect, the start and end of the processing phase on each channel is also printed to the console. So let’s see the results:
| ER7 | JSON |
Preprocessor log | 0.000s | 0.000s |
Given Name Output | 0.007s | 0.003s |
Postprocessor log | 0.027s | 0.031s |
Total | 0.034s | 0.034s |
Well, the first time I saw this numbers I couldn’t believe what I was seeing. To those of you who don’t know how Mirth does it’s internals regarding Javascriot, it uses Rhino, an open-source implementation of JavaScript written entirely in Java that does pretty well in parsing JSON.
These two channels don’t really do much processing (only print to the console the given name) so we can see the impact of switching from ER7 to JSON when using Mirth Connect. But the really important test is when we change from MLLP to HTTP and Mirth Connect can use both.
REST Webservice on Mirth Connect
For this test, we’ve sent the same JSON message as a POST using the Postman REST client application for Chrome. The same timings as above but now with HTTP. For the ER7 message, a MLLP server was configured to measure the impact of a TCP server.
| ER7 | JSON |
Preprocessor log | 0.000s | 0.000s |
Given Name Output | 0.006s | 0.003s |
Postprocessor log | 0.038s | 0.076s |
Total | 0.044s | 0.079s |
As expected, the use of a REST web service, using the Jetty embedded web server used on Mirth Connect couldn’t be as fast as a simple TCP server like the one used on a MLLP listener. Nevertheless, the benefits of using HTTP instead of pure TCP sockets might be sufficient to forget this performance penalty in many scenarios, like refered on my previous post.
As a conclusion and with simple tests and data, the performance impact of using JSON instead of ER7 doesn’t seem important. A stress test, with concurrency, is necessary to verify if it can handle a real life scenario.
By Alexandre Santos