craysiii / twitchbot

MIT License
5 stars 0 forks source link

CPU core spiking to 100% due to MessageQueuePlugin interval #9

Closed craysiii closed 3 years ago

craysiii commented 3 years ago

https://github.com/craysiii/twitchbot/blob/2dced4703b5b9500e42467fa66dc9f37596c0b6b/lib/twitchbot/plugin/message_queue_plugin.rb#L12

When running a bot, the CPU core that ruby is running on will spike to 100% usage. This seems to be due to the interval that the MessageQueuePlugin is supposed to fire off #send_message.

After testing further testing, it appears that this only happens when certain values < 1 are used, such as 30/7200 (0.004166666 repeating), which corresponds to the amount of messages one can possibly send with the highest permissions to the twitch servers. After messing about, I was able to determine that literals such as 0.004 and even 0.001 do not exhibit the same CPU spikes.

This appears to be related to how eventmachine schedules timed events. More research needs to be done to conclude this though.

craysiii commented 3 years ago

This is actually due to integer division and I completely missed it.

Need to force float division and the issue will be fixed.