If multiple requests to set data in the same sorted map are done at once, does the sorted map handle them all at once, or in a queue.
Based on the ability to have 100,000 requests per second, I would assume they are done simultaneously, but having an exact answer would help.
I have this question because I have a global counter variable in my game, and I want to know if it’s theoretically possible for 2 servers to try to add a number to the global counter at the same time where:
- Server1 grabs the current sortedMap value
- Server1 adds it’s number to the sortedMap value
- Before Server1 sets it’s new value to the sortedMap, server2 grabs the sortedMap value
- Server1 updates the sortedMap value
- Server2 adds it’s number and sets it to the memoryStore.
In this example server1’s number would be completely ignored.
If they are handled in a queue then the following would happen in the same situation:
- Server1 is entered into the sortedMap queue, and since its first is taken off the start its operations.
- Server1 grabs the current sortedMap value
- Server1 adds it’s number to the sortedMap value
- Server2 is added into the sortedMap queue, and since server1 is still not done computing, it waits.
- Server1 updates the sortedMap value, and is taken off the queue
- Server2 is now first in the queue and starts it’s operations
- Server2 grabs the sortedMap value
- Server2 adds it’s number and sets it to the memoryStore.
Now I have already come up with a way to completely avoid this problem, so it’s not a super high priority, but I would like to know for future projects.