Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Improving discord bot

56 views
Skip to first unread message

Jerry

unread,
Nov 28, 2018, 2:21:41 AM11/28/18
to
Hi all,

I have been using discord.tcl (https://github.com/Unknown008/discord.tcl) (forked from https://github.com/qwename/discord.tcl) for a while now and since the original author dropped the project, I have been passing some edits to the code, and most of it is working well. The yesterday it came to my attention that the bot was using a bit too much RAM (64 MB) and I started thinking about ways to bring memory usage down.

One of the things I believe is part of that problem is the huge dictionaries that are kept in memory. I believe the biggest one has a key for each server ID and the value is another dictionary containing things such as server name, server owner name and ID, members and each of these member's info, in brief, it's pretty big (my test discord bot is in 2 servers and the dict is slightly over 12k long characters (sorry I'm not good at performance related things so maybe I'm off the mark here)). That dict's name is [set ${::session}::guilds] (usually $::discord::session::0::guilds) and there are a few other similar dicts, one for users, one for channels and one for dmChannels (latter two are not as big).

My live bot is currently in about 6 servers with a larger number of users than my test bot and I'm still adding more "features" to the bot.

I'm thinking of changing the source code to put these data into an sqlite3 database and query it each time I need the data, but it's going to take me some time and I haven't settled on its structure yet. In the meantime, I would like a second opinion on whether I'm on the right track or not, or how I can do it better, or let me know if I can provide some information that would help you understand my issue better.

Or maybe the main issue is elsewhere, with the large pool of procs that have been defined or with the event listeners? Is there even any way I could improve the memory usage there?

PS: The actual script that uses discord.tcl can be found here: https://github.com/Unknown008/MarshtompBot

Thanks,
Jerry

Andreas Leitgeb

unread,
Nov 28, 2018, 4:49:00 AM11/28/18
to
Jerry <jerryysk.s...@gmail.com> wrote:
> the bot was using a bit too much RAM (64 MB)

Are you running this on previous-millennium hardware?
(Otherwise I can't understand how 64MB would be an issue)

Jerry

unread,
Nov 28, 2018, 5:24:28 AM11/28/18
to
Well it's just that the server is being rented with 256 MB of RAM. Would, in your opinion, 64 MB of memory usage be something that an application of this type would need?

Jerry

unread,
Nov 28, 2018, 5:26:36 AM11/28/18
to
On Wednesday, November 28, 2018 at 1:49:00 PM UTC+4, Andreas Leitgeb wrote:
Oh I should probably also mention that it's not the only application on the server and right now this bot is the one that is consuming the most memory.

Rich

unread,
Nov 28, 2018, 6:55:00 AM11/28/18
to
According to top, just starting a tclsh requires 34MB, and just
starting a wish requires 72MB (both just sitting at their respective
CLI's) on a 64-bit system.

So 64MB usage, if the base tclsh uses 34MB means your extra data is
taking 30MB beyond what is needed just to have a Tcl interpreter
running. Whether that seems like a lot depends upon perspective. In
a VM with 256MB ram, yes, 30MB used is a fair chunk. But is it worth
your effort to squeeze this, when the simpler solution might be to
upgrade to a VM with 512MB?
Message has been deleted

Jerry

unread,
Nov 28, 2018, 8:07:34 AM11/28/18
to
On Wednesday, November 28, 2018 at 3:55:00 PM UTC+4, Rich wrote:
> According to top, just starting a tclsh requires 34MB, and just
> starting a wish requires 72MB (both just sitting at their respective
> CLI's) on a 64-bit system.
>
> So 64MB usage, if the base tclsh uses 34MB means your extra data is
> taking 30MB beyond what is needed just to have a Tcl interpreter
> running. Whether that seems like a lot depends upon perspective. In
> a VM with 256MB ram, yes, 30MB used is a fair chunk. But is it worth
> your effort to squeeze this, when the simpler solution might be to
> upgrade to a VM with 512MB?

All right, thanks for the input, that's very informative and eye opening :) I think I'll be upgrading the memory
0 new messages