Errbot Slack client taking long to start
In order to let us help you better, please fill out the following fields as best you can:
I am...
- [ ] Reporting a bug
- [ ] Suggesting a new feature
- [X] Requesting help with running my bot
- [ ] Requesting help writing plugins
- [ ] Here about something else
I am running...
- Errbot version: 5.2.0
- OS version: CentOS 7
- Python version: 3.6
- Using a virtual environment: yes
Issue description
We are using errbot with Slack. My problem is that starting the bot takes a really long time ~5 minutes. Im wondering what could be the cause for the slow start? FYI, our slack environment is huge (~30k members and ~20k channels).
Steps to reproduce
start the bot, watch the logs. Takes about 5 minutes to start.
Additional info
If you have any more information, please specify it here.
A few ideas for you:
Is there any way for you to turn on debug logging look through those logs?
How many plugins are you running?
If you disable all plugins, and then enable them all one by one, you should probably be able to track which specific plugin is making the bot slow to start.
As far as I know, errbot itself (including the slack backend) doesn't do any looping through channels or users or anything like that, it just opens a socket to Slack and listens for events. I'm going to bet that there's a plugin somewhere that is taking a long time to load up. I could be wrong, though, I'm not an expert :)
Hope that helps!
This came up for us as well - it turns out that the problematic part is in slackclient, as it tries to check for duplicates for channels when attaching a channel, and thus iterating through all of them in a SearchList object. This is happening with an older version (1.3.2), which errbot is depending on right now.
Here is the result of profiling for us:
Thu Sep 26 17:13:39 2019 profile.txt
204729560 function calls (204702609 primitive calls) in 102.379 seconds
Ordered by: cumulative time
List reduced from 5162 to 20 due to restriction <20>
ncalls tottime percall cumtime percall filename:lineno(function)
665/1 0.015 0.000 102.379 102.379 {built-in method builtins.exec}
1 0.000 0.000 102.379 102.379 errbot:3(<module>)
1 0.000 0.000 102.140 102.140 cli.py:88(main)
1 0.000 0.000 101.967 101.967 bootstrap.py:204(bootstrap)
1 0.000 0.000 101.708 101.708 base.py:687(serve_forever)
1 0.000 0.000 101.707 101.707 slack.py:358(serve_once)
1 0.001 0.001 98.858 98.858 client.py:121(rtm_connect)
1 0.000 0.000 98.857 98.857 server.py:88(rtm_connect)
1 0.000 0.000 96.868 96.868 server.py:170(parse_slack_login_data)
3 0.041 0.014 96.865 32.288 server.py:207(parse_channel_data)
20180 0.075 0.000 96.856 0.005 server.py:308(attach_channel)
20180 47.857 0.002 96.756 0.005 util.py:3(find)
203606110 48.892 0.000 48.892 0.000 channel.py:11(__eq__)
172 0.000 0.000 2.352 0.014 _socket.py:76(recv)
172 0.000 0.000 2.352 0.014 ssl.py:990(recv)
172 0.000 0.000 2.352 0.014 ssl.py:866(read)
172 0.000 0.000 2.351 0.014 ssl.py:624(read)
172 2.351 0.014 2.351 0.014 {method 'read' of '_ssl._SSLSocket' objects}
6 0.000 0.000 2.320 0.387 client.py:213(rtm_read)
6 0.000 0.000 2.320 0.387 server.py:274(websocket_safe_read)
The server maintains a list of channels already added, and checks agains that list sequentially every time a new channel is attached, and ends up doing (n * (n+1) / 2) comparisons. As this is quadratic, the number gets big enough quite fast.
At the same time, there is a version 2 for the slack client already, do you see any work going towards using that in errbot?
actually encountered this today, any plans to promote slackclient 2.x as a connector or is this handled by the other issue around deprecation plans for slackclient? asking as unsure on this as the issue is pretty old.
You could give slackv3 backend a try https://github.com/nzlosh/err-backend-slackv3
Use slack-v3 backend.