Adventures in BEAM optimization with our MQTT adapter
The author shares their experience of optimizing Elixir code for an MQTT protocol adapter, only to discover that the true solution to performance issues was an obscure setting in the Erlang VM controlling which system call the IO polling subsystem used. They initially spent time profiling and optimizing the code but found that the majority of CPU usage was due to SLEEP calls, which they later realized were a measurement artifact. After disabling masking for WebSocket pings and adding special cases for MQTT pings, they continued to see high CPU usage. They eventually discovered that enabling +K true in the Erlang runtime significantly reduced CPU usage by switching from poll to epoll system call for IO polling. The author's micro-optimizations were ultimately irrelevant as the majority of CPU cycles were spent on IO polling.
Company
Ably
Date published
July 17, 2020
Author(s)
Simon Woolf
Word count
1724
Language
English
Hacker News points
None found.