3 Months of hosting SGMRT_bot. What have i learnt?

Koh Chi Hao
2 min readNov 5, 2017

It’s been 3 months since I hosted my SGMRT_bot. During the explosion of the vulcan post on Facebook. There was a sudden increase in the amount of people using it. From the initial less than 100 subscribed users to now 7200 subscribed users. It was a roller coaster ride for me as well. Initially, the code wasn’t planned to handle so many users and everything was done in a poor sequential way.

For instance, when there is a breakdown detected. I would sequentially send out all 7000 users. Little did I know, this have caused an spike in the RAM usage and cause the server to breakdown(how ironic). So, half of the people wouldn’t have received the notification at all which I didn’t noticed until i checked the logs of the server. This is where i decided to look into concurrency and queues to send the notifications in batches. In Telegram, you cannot send more than 31 messages per second at one go. Hence, I’ve set to send 29 messages per second to be sent at one go. The downside to this is that the total time to send out all the messages is roughly 2mins~ which is still within the acceptable range.

Since, SGMRT_bot was built on NodeJS, I’ve looked into some readily available libraries. Here is the library I used to solve my problem :

  1. P-queue https://github.com/sindresorhus/p-queue

This have drastically brought down the RAM usage to well within the acceptable range of my server. So now when there is a train breakdown detected, the server would send in batches of 29 messages at one go.

You can find the telegram bot here : https://goo.gl/F6r8Sd
Feel free to support the server : https://goo.gl/HTK2Xf
My website : www.kohchihao.com

Thanks for reading this article :)

--

--