When you’re implementing a new feature or switching to a different library, your application may start to underperform. We just ran into that exact

Why so slow? Using Profilers to Pinpoint the Reasons of Performance Degradation

submited by
Style Pass
2022-05-12 10:30:03

When you’re implementing a new feature or switching to a different library, your application may start to underperform. We just ran into that exact problem, but with the combination of profilers, we were able to identify and reduce the bottleneck we introduced. In this article, we would like to show you how we pinpointed the bug that caused our performance issues so you know how to approach the problem if you ever run into it.

As you might already know, you can connect to Memgraph using Bolt protocol, which you can think of as the HTTP protocol for querying graphs stored in Memgraph. Partially because of our WebAssembly client and partly because of the increasing popularity of WebSocket, we decided to provide an option for our users to use Bolt over WebSocket to run queries against Memgraph. But first, we had to face the elephant in the room: our handwritten Bolt server. It was completely handwritten from scratch on top of the POSIX API. Supporting WebSocket would mean implementing everything for it, for example, parsing HTTP requests or encoding/decoding WebSocket frames. Ancient developer wisdom advises never to write your own cryptographic library, so the first thing in our minds was: We shouldn’t write our own WebSocket library. In Memgraph 2.2 we released a monitoring server via WebSocket, which was written using the very popular Boost.Asio library. It was our experiment with Boost.Asio and WebSocket. As you might guess, based on Memgraph 2.3 and this post, we were happy with the result, so we opted to use Boost.Asio to rewrite our Bolt server.

And that’s when our problems started. We were newbies at using Boost.Asio in a production environment, so it took us some time to learn the dos and don’ts about the library and implement the same functionality as we have with our previous server implementation. We made it work! All of our tests were passing, and we were happy… But then we checked the benchmarks: the performance of Memgraph had plummeted. We knew that we had to compare our new code with the old implementation, but we hadn’t noticed anything strange. Because the code comparison was a dead end, we decided it was time – dramatic music intensifies – to reach for profilers.

Leave a Comment