LuckPerms

LuckPerms

41.4k Downloads

[Inquiry] LuckPerms Connection Frequency and Ideal Connection Pool Size

A248 opened this issue · 2 comments

commented

I already know that LuckPerms uses HikariCP for connection pooling, and there is some ideal connection pool size. The default setting is 10, but I realised that this could not possibly be the ideal setting for servers of all sizes – servers with more players would undoubtedly require more connections. That said, it is possible that the default value of 10 encompasses a scope of optimisation such that even large deviations in player count would not be cause for a substantially different pool size. However, I understand a connection can take anywhere from 200ms to 600ms on localhost, and I'm using a database on localhost, meaning I seriously doubt that the default value of 10 is such that other details may be neglected.

Let that 200ms-600ms be 1 second for good measure, and it appears that the default value of 10 is considerably high for a server such as mine. If I do not make any permissions changes and LuckPerms only connects to the database when a player logs in, I estimate that I should use not more than 4 connections, since I can expect, only in the extreme, for 4 players to log in over the course of 1 second. As a reminder, this is pre-supposing I do not make any permission changes and LuckPerms only connects on player login.

What I do not know is how often LuckPerms connects to the database and when LuckPerms connects to the database, specifically., what kinds of actions trigger connections. Does LuckPerms connect when a player joins? Does it connect instantaneously in order to save data after a permissions update? Does it queue changes in the background and save periodically? Does it save the user's data when he/she quits the game? While the user is online, does it only store certain information about the user where required, and connect when different information is necessary, or does it retain all of a user's relevant information while the user is online?

I have searched the existing Github issues and the LuckPerms wiki about this but little information has come up. LuckPerms' wiki links to the HikariCP wiki, which I have read previously with regards to other topics. Since the ideal connection pool size is most certainly dependent on how often LuckPerms connects, I determined that it was necessary to know the latter.

commented

So first of all LP is continually conntected to the database. The existing connections are held open while the plugin runs (and reopened should one close).

Also a joining player needs more than one connection. In order to load data as fast as possible database queries are executed in parallel. Meaning that each query uses one of the connections in the pool. To load a player roughly 4 queries are needed and that data is cached in memory for performance.

Now LP saves the data to the database immediately when a changed triggered by a command happens or when the save method is invoked through the API.
/lp sync or a network sync causes LP to reload either all data or all affected data, which naturally needs quite a few querries and that's where the pool is most relevant.

Now onto your original question. The pool is configured for a server with 4 cores and a constant stream of querries (4 cores because that's pretty common). Now since under pretty much all circumstances you never get anything but a burst of queries, adjusting the value for more cores is pointless. In short the 10 connections is more than you'll ever need, but having them doesn't hurt. 10 are sufficient for huge servers and you really should only ever touch that value if you know what you're doing or if there's a specifc need (like reducing them due to restrictions from the database server).

How to calculate the ideal pool size can be found in the Hikari docs if you're really interested in finding the perfect value. Also the hikari docs go into great lengths explaining how using a connection pool improves performance and what you need to know about it from a very basic level right down to justifications for design decisions.

commented

Thank you, this is exactly what I was looking for. My CPU is 4 cores, so that's perfect.