Raise match errors create CPU load!

Hi everyone.

I am using Elixir for a reverse proxy on one of our protocols on TCP.

The project is fully open sourced. https://github.com/alisinabh/ZigorProxy

My recently noticed that on just about 100 users i get about 0.7% CPU utilized (XEON E5-2620v3)
I tested many things and as you can see in branch “matchfix” i have made it more optimized by preventing match errors. now i got CPU around 0.1% utilized on 100 users

My questions are:

  • Is there any overhead on raising exceptions? (since we say, let it crash! it should’t be)
  • Does elixir need a config for deployment so raising exceptions wont create load on server? or i am making a huge mistake and utilizing my CPU?
  • Is There any performance difference between spawning a new process and creating a new task? if there is, which one is better?
1 Like

Yes exceptions have overhead and are not free. Let it crash means that ‘unplanned exceptions’ should crash. In all other cases you should properly handle and try to prevent exceptions as normal unless if dying is really fine to wipe it all. I try to never catch exceptions. That is why you should use the tuple-returning variants of ‘bang’ functions in elixir if you really can handle the error instead of setting up an exception handler. Constructs like with help this a lot. This is also why I am a fan of libraries like exceptional as I think it really did a lot of error handling better. :slight_smile:

Not really, exceptions are costly and should be avoided. In my opinion, if an exception happens then I try my best not to handle it as it should truly be an ‘exceptional’ condition and I want that logged so I can fix it.

Nope, creating a task ‘is’ spawning a new process, just with some nice helpers. :slight_smile:

3 Likes