Tag: jackson

  • CometD 2.4.0.beta1 Released

    CometD 2.4.0.beta1 has been released.
    This is a major release that brings in a few new Java API (see this issue) – client-side channels can now be released to save memory, along with an API deprecation (see this issue) – client-side publish() should not specify the message id.
    On the WebSocket front, the WebSocket transports have been overhauled and made up-to-date with the latest WebSocket drafts (currently Jetty implements up to draft 13, while browsers are still a bit back on draft 7/8 or so), and made scalable as well in both threading and memory usage.
    Following these changes, BayeuxClient has been updated to negotiate transports with the server, and Oort has also been updated to use WebSocket by default for server-to-server communication, making server-to-server communication more efficient and with less latency.
    WebSocket is now supported on Firefox 6 through the use of the Firefox-specific MozWebSocket object in the javascript library.
    We have performed some preliminary benchmarks with WebSocket; they look really promising, although have been done before the latest changes to the CometD WebSocket transports.
    We plan to do a more accurate benchmarking in the next days/weeks.
    The other major change is the pluggability of the JSON library to handle JSON generation and parsing (see this issue).
    CometD has been long time based on Jetty’s JSON library, but now also Jackson can be used (the default will still be Jetty’s however, to avoid breaking deployed applications that were using the Jetty JSON classes).
    Jackson proved to be faster than Jetty in both parsing and generation, and will likely to become the default in few releases, to allow gradual migration of application that made use of Jetty JSON classes directly.
    The applications should be written independently of the JSON library used.
    Of course Jackson also brings in its powerful configurability and annotation processing so that your custom classes can be de/serialized from/to JSON.
    Here you can find the release notes.
    Download it, use it, and report back, any feedback is important before the final 2.4.0 release.

  • CometD JSON library pluggability

    It all started when my colleague Joakim showed me the results of some JSON libraries benchmarks he was doing, which showed Jackson to be the clear winner among many libraries.
    So I decided that for the upcoming CometD 2.4.0 release it would have been good to make CometD independent of the JSON library used, so that Jackson or other libraries could have been plugged in.
    Historically, CometD made use of the Jetty‘s JSON library, and this is still the default if no other library is configured.
    Running a CometD specific benchmark using Jetty’s JSON library and Jackson (see this test case) shows, on my laptop, this sample output:

    Parsing:
    ...
    jackson context iteration 1: 946 ms
    jackson context iteration 2: 949 ms
    jackson context iteration 3: 944 ms
    jackson context iteration 4: 922 ms
    jetty context iteration 1: 634 ms
    jetty context iteration 2: 634 ms
    jetty context iteration 3: 636 ms
    jetty context iteration 4: 639 ms
    Generating:
    ...
    jackson context iteration 1: 548 ms
    jackson context iteration 2: 549 ms
    jackson context iteration 3: 552 ms
    jackson context iteration 4: 561 ms
    jetty context iteration 1: 788 ms
    jetty context iteration 2: 796 ms
    jetty context iteration 3: 798 ms
    jetty context iteration 4: 805 ms
    

    Jackson is roughly 45% slower in parsing and 45% faster in generating, so not bad for Jetty’s JSON compared to the best in class.
    Apart from efficiency, Jackson has certainly more features than Jetty’s JSON library with respect to serializing/deserializing custom classes, so having a pluggable JSON library in CometD is only better for end users, that can now choose the solution that fits them best.
    Unfortunately, I could not integrate the Gson library, which does not seem to have the capability of deserializing arbitrary JSON into java.util.Map object graphs, like Jetty’s JSON and Jackson are able to do in one line of code.
    If you have insights on how to make Gson work, I’ll be glad to hear.
    The documentation on how to configure CometD’s JSON library can be found here.
    UPDATE
    After a suggestion from Tatu Saloranta of Jackson, the Jackson parsing is now faster than Jetty’s JSON library by roughly 20%:

    ...
    jackson context iteration 1: 555 ms
    jackson context iteration 2: 506 ms
    jackson context iteration 3: 506 ms
    jackson context iteration 4: 532 ms
    jetty context iteration 1: 632 ms
    jetty context iteration 2: 637 ms
    jetty context iteration 3: 639 ms
    jetty context iteration 4: 635 ms