-
Notifications
You must be signed in to change notification settings - Fork 112
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: in-house queue system #279
Conversation
lib.print.info('Preventing hardcap from starting...') | ||
CancelEvent() | ||
end | ||
end) | ||
|
||
if GetResourceState('hardcap'):find('start') then | ||
lib.print.info('Stopping hardcap...') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should these be debug prints instead of info?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think so, the average user may be confused on why hardcap was stopped.
self.size -= 1 | ||
totalSize -= 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the difference between self.size and totalSize?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
self.size
is the size of the sub-queue of the player and totalSize
is the total size of all queues combined. I created totalSize
instead of a calculate function to not have to calculate the value all the time for all players every second.
function prototype.enqueue(self, license) | ||
self.size += 1 | ||
totalSize += 1 | ||
self.positions[license] = self.size |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What alternatives were considered for the queue data structure here?
What are the tradeoffs of having the map being size to license rather than license to size? What are the tradeoffs to storing both maps? What are the access patterns? How often are we asking for the first player in line vs asking what position in line x player is in?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The tradeoff of having license to position is that a less performant loop has to be done when a player is removed from the queue, but the tradeoff of having only position to license is that each time we want to know the position of a player we need to loop. Meaning either we use license to pos and make a less performant loop every time a player disconnects (since it's done through lua), or we use pos to license/source and make a more performant loop every time a player disconnects (I've imagined that table.remove
would be used since iirc it uses a C loop which should be faster) but then to get players updated on their position the map would be looped through every second for every player.
I've mapped it license to position because the way I've imagined it is that each player knows their position in the queue and nothing more. I think the only good reason to store position to license/source would be if we need to reveal to another player or an external API what the player in a certain position is, but at the moment the queue does neither, so no reason to store that information currently.
Since the player is updated on their status every second, the position of the player in the queue has to be known every second, but currently it is never asked in what position in line another player is.
Closing to break up into smaller PRs |
Description
Adds an in-house queue system.
The system includes:
playerJoining
event (meaning while the player was downloading the server), wait a configurable amount of seconds for the player to connect back before removing.Some parts of the code may look weird/unnecessary as I've attempted to make it as performant as I can.
I've tested this as much as I can but this still requires further testing for race conditions, edge cases, and other unexpected things that I'm not able to test by myself.
Adaptive card preview:
![image](https://private-user-images.githubusercontent.com/43699941/289310378-de79da74-ec67-4a6f-913f-7fee101e44c8.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjA5ODczMTMsIm5iZiI6MTcyMDk4NzAxMywicGF0aCI6Ii80MzY5OTk0MS8yODkzMTAzNzgtZGU3OWRhNzQtZWM2Ny00YTZmLTkxM2YtN2ZlZTEwMWU0NGM4LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA3MTQlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwNzE0VDE5NTY1M1omWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTEyYTY3NjY0M2MxZjg2ODE4NjFiZjZhNzUyZGE3YmU0ODcwZjFmMjRiMDU3ZDUzZDQ4NzQyNmUyM2JlMWM2NWImWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.Mqd5nHGmXOMM6fYLBzTBHyaYD6NG4fOvJVbcUVukuEo)
Checklist