hashrocket / websocket-shootout

A comparison of websocket servers in multiple languages and frameworks
MIT License
429 stars 76 forks source link

JSON and the C++ benchmark #20

Closed ArashPartow closed 7 years ago

ArashPartow commented 8 years ago

I don't think this was intentional, but it seems that one of the slowest C++ JSON parsers out there was used for the C++ benchmark. Perhaps a review of the following might help:


Also with regards to the following: https://github.com/hashrocket/websocket-shootout/blob/master/cpp/src/server.cpp#L48

Perhaps having a per thread instance of the JSON reader and variables available (seeing as though io_service is being threaded), instead of constructing and destructing the instances on each call of _onmessage.

Types such as Json::Reader (r instance) may sometimes be relatively expensive to construct/destruct.

jackc commented 8 years ago

I'm open to replacing the JSON parser with something else, but my initial guess is JSON parsing is not a bottleneck. If I get a chance I'll try implementing rapidjson (or a PR is welcome...)

ArashPartow commented 8 years ago

@jackc You're right, the change of JSON parser wont bring in a 10x or 2x increase, though I did a quick change and rerun of the benchmark, and the improvement observed seems to be about ~8% from the vanilla version of the benchmark.

jackc commented 7 years ago

It's not exactly apples-to-apples but I used RapidJSON for the uWS benchmark. Not sure how much of a performance difference it makes but it's more verbose / harder to use.