GoAccess improvements and the importance of error checking

GoAccess is an open-source real-time web log analyzer. It sports curses and web interfaces. It looks really pretty and I like that :)

Upstream has already accepted my patch to allow a build on NetBSD which is nice.

However, there is still a serious issue - GoAccess burns a LOT of CPU. With older versions it wasn’t too onerous, but now it uses 4 threads and CPU was going through the roof on my poor web server. Luckily it turned out it was a simple patch.

This is a good example of why we always want to check for errors. POSIX usleep documents that if a value of 1000000 or greater is given then EINVAL is returned immediately. The default value GoAccess was using for following the tail of the web log file was also defined as 1000000, which means on a POSIX compliant OS like say NetBSD, the usleep call did exactly nothing. Hence burning the CPU time. With this patch, CPU time is now barely measureable :)

But we can still make it GoFaster :D

While the CPU was being pegged I noticed it was stuck in the select state. Well, select(2) is not the greatest API ever made. Luckiy, we now have poll(2) which is a massive improvement and as it’s a POSIX standard, highly portable as well. After a few hours of work, I turned out a a fairly complex patch and it works very well! It’s been running on my web server all night and the websocket just ticks over. The web page I’m looking at constantly updated itself.

Huge win for my low powered server, now consuming less power and a great start to the New Year!