Service returning json - tooltwist/xdata GitHub Wiki
This benchmark does not strictly measure XData performance, but rather the combination of several factors:
- does the service convert JSON to XML before returning the data?
- the cost of the calling mechanism (XPC or XDS).
- is the complete data used, or only part of the data (sparce access).
In any case the data is interesting from an XData point of view, as the results show the comparative differences of various data formats and parsers.
The tests were performed using the ToolTwist XPC and XDS libraries. XPC is a protocol that's been in use since 2001 in hundreds of applications. XDS is a rewrite of XPC with performance enhancements and support for version 2 of XData. These service calling protocols have no significant impact on the benchmark results, other than that they sometimes force the use of a specific parser (See the section below on XPC and XDS Calling Times).
Summary
To access a 12,000 line JSON document:
- The past approach of using an XPC to convert JSON to XML costs ~328ms per call.
- The standard Java XML parser requires ~210ms to parse and access the data once it's in XML format.
- Using XDS and returning JSON directly allows the data to be accessed in ~7ms.
- Accessing all 9,230 fields in the data only increases this access time to ~15ms.
Benchmark Description
This test is the equivalent of an application using an XPC/XDS service to access data from a remote RESTful service, but uses dummy data to exclude the unrelated and highly variable time of calling the remote service. There are three scenarios tested, each calling it's service ten times and checking the data returned each time. In each case data from a 12,000 line JSON document is parsed and the accessed by the application. This benchmark is intended to simulate a data-heavy application.
Note that the same XData API is used to access the data, irrespective of the format in which it is returned.
xpc_json2xml
This test calls an XPC service that first converts the JSON data to XML, and then returns that XML. Unfortunately XPC uses DOM to parse the XML, forcing conversion to xml-dom. This is equivalent to the legacy situation used in many applications.
xds_json2xml
This test calls an XDS service that first converts the JSON data to XML and returns that XML. XDS allows "xml-fast" to be used.
xds_json
This test call an XDS service that returns the JSON without conversion (i.e. "json-fast")
Some formats perform especially well when only a few fields need to be accessed within the data set.These tests are repeated (the "sparceAccess" tests), but in this case only a single element in the returned data is accessed.
Benchmark Results
In each of the following tests the service was called ten times.

Benchmarks were performed using JUnitBenchmarks. Thanks to Carrot Labs.
Understanding these results
xpc_json2xml
This test is equivalent to the code currently used in many applications. The data is accessed from a remote RESTful service as JSON but needs to be consumed as XML. In this implementation there are two major performance costs:
- converting JSON to XML, and
- parsing XML using DOM parser
The XPC format uses the DOM Document object to determine routing, and this used standard Java XML parsing, as used by most Java applications. (format=xml-dom)
Notice that the sparceAccess times for this test (xpc_json2xml_sparceAccess) are almost exactly the same - once the document has been converted to Java objects, access is relatively quick irrespective of whether you access one field or all of them. Another way of looking at this, is that the standard Java XML parser always prepares for the worst case.
xds_json2xml
This test is similar, but avoids DOM parsing by using the new XDS interface. The data gets returned in the default XData format for XML. (format=xml-fast)
xds_json
This final test skips the JSON to XML conversion all together and returns the data as JSON. Data is returned in the standard XData format for JSON. (format=json-fast)
##Evaluating the numbers
-
We'll consider the call times for XPC and XDS to be too small to be significant. See XPC and XDS Performance for details.
-
XData's Fast JSON and Fast XML parsers have similar performance, so ( (xds_json2xml - xds_json) ) is the time to convert the data from JSON format to XML.
(Time to convert JSON to XML = 133ms - 15ms = ~118ms) -
If we subtract the time to convert to XML from the first test case, we are left with the time to parse and access data using the normal Java XML parser.
(xml-dom: time to parse and access = 328ms - 118ms = ~210ms) -
The third test case (xds_json) is simply the time to parse and access using XData's Fast parser.
(json-fast: Time to parse and access every field: ~15ms) -
For the third test case (xds_json), the advantages of XData's Fast parser become apparent. If only a few fields need to be accessed, most of the parsing effort is avoided. (json-fast: Time to parse and access a single field: ~7ms)
--