High tick usage when using DiscordSRV JDBC connection
TraceLTRC opened this issue ยท 10 comments
Description
Luckperms is using tons of tick time to do a function called ExpiringCache.get() when DiscordSRV is connected using a database. You can see it from this spark report (https://spark.lucko.me/zBMwyRdauw). This might be DiscordSRV's issue, but the fact that It is luckperms that's showing up on the spark report is confusing to me, which is why i opened the issue here.
Reproduction steps
- Create a Waterfall server, an Airplane server, and a MySQL database with roughly 100ms ping.
- Add Luckperms to waterfall server and airplane server, both using the same MySQL database for storage.
- Add discordSRV to airplane server and add JDBC string to connect to the database.
- Run the servers and add players
Expected behaviour
Server should run normally with no lag from LuckPerms or DiscordSRV. But from running a spark report, it'll show that Luckperms is using most of the server resources on a function called ExpiringCache.get(). This leads to tick spikes of 100ms to 3000ms.
Environment details
- Server type/version:
Airplane
running version1.16.5
buildf5fb024
- Server type/version:
Waterfall
running version1.16.5
build412
- LuckPerms version:
v5.3.30
- DiscordSRV Version:
1.22.0
Try disabling the LuckPerms context integration in DiscordSRV, I imagine that is probably what the problem is.
It's a known issue: #2788 (comment)
@Vankka did you manage to get anywhere at the DSRV end? If not, it might be worth automatically disabling the contexts integration if the user is using MySQL...
Ah I should've done some research first, it seems you have, awesome! DiscordSRV/DiscordSRV@e6e4fa3
@TraceLosu Are you sure you're using an up-to-date version?
The version specified by OP is up-to-date. I've also tried looking through some of the parts that could be the culprit, but haven't found anything. Also not helping matters, the spark report doesn't show any children for ExpiringCache for some reason (I'm guessing it's not taking 2.5s itself)
Also Edit: if you have questions regarding DiscordSRV's code for this, I'm at your disposal, I'll check on this issue for any questions
Also not helping matters, the spark report doesn't show any children for ExpiringCache for some reason (I'm guessing it's not taking 2.5s itself)
ExpiringCache
is a cache - and has measures in place (locking) to ensure that only one thread does the actual calculation while the other threads wait.
I think this line is what's causing the problem:
DiscordSRV should always provide the cached value.
See here for more info: https://javadoc.io/doc/net.luckperms/api/latest/net/luckperms/api/context/ContextCalculator.html
Context lookups should be fast: lookup methods are likely to be invoked frequently, and should therefore be fast to execute. If determining the current contexts involves a particularly time consuming lookup (database queries, network requests, etc), then such results should be cached ahead of time.
getDiscordId
provides the cached value if there is one, and players that are online are kept in the cache (unless mysql takes >30 seconds to respond to the query, which I doubt is happening). I changed it to only use cached data though, it's available on development builds: https://snapshot.discordsrv.com
@TraceLosu Could you confirm if fixed please :)
Will do! Just need to wait until my server's scheduled restart.