Performing a Game Server Stress Testing Efficiently
…On command, thousands of fearless clones rushed down dark, narrow corridors of the Web to face the battle and to win. The clones had no magic attack skills nor legendary armor, but they followed instructions obediently, which brought them a glorious victory.
It’s not a piece from the Star Wars saga, but a stress testing algorithm for a Java-based server that our game development crew used in one of the recent projects — a Poker game application for social networks. This algorithm is easy for implementation, not to mention it ensures quite a high skill level of the game for automatic players. Using this method, it’s possible to use bots for testing alongside real players without spoiling the fun.
Stress testing for a game server
In the initial stage of game development, when we were working on the flash-client, we needed to test the game server features and evaluate its performance. This task required both integration and load tests; we decided to write an instruction algorithm for poker automated players or, to put simply, bots.
Due to this algorithm, numerous bot clones in social networks could change their playing manner depending on game situation and the hands they had. While developing the algorithm, we didn’t set any ambitious goals like endowing bots with powerful skills of a Poker guru, so the implementation was rather simple. Yet, it turned to be quite an effective tool and allowed us to test the game server using bots along with real users. Often our bots seized victories from humans, although not because of exceptional skill but, plainly, by number.
How does the algorithm work?
While developing the Java-based game server, we used module testing that allowed to check functions of separate classes. The same tests were used when developing the engine ‘brains’ — the calculator of a winning hand, i.e. the game component that chooses the player with the highest-ranking hand who wins that particular deal.
As you know, the Poker hand categories include:
- Straight flush — a hand that contains five cards in sequence, all of the same suit.
- Royal flush — an ace-high straight flush: Ace, King, Queen, Jack, 10.
- Four of a kind — a poker hand that contains all four cards of one rank.
- Full house — a hand that contains three matching cards of one rank.
- Flush — a poker hand where all five cards are of the same suit.
- Straight — a poker hand that contains five cards of sequential rank in at least two different suits.
- Three of a kind — a poker hand that contains three cards of the same rank.
- Two pair — a poker hand that contains two cards of the same rank, plus two cards of another rank.
- One pair — a poker hand that contains two cards of one rank.
- High card — a poker hand made of five cards that don’t fit any of the above combinations.
Since we have ten high-rank hand categories, for a simple case it requires 10 calculation cycles to find the solution. Although, even a complete beginner will notice that some combinations have similar properties. For example, the Straight Flush obtains properties of both Straight — five cards of sequential rank — and Flush — all cards of the same suite. Knowing this peculiarity, we could reduce the number of cycles to 4.
As a result, we obtained a set of module testings for each combination but we weren’t completely sure that our calculations were right. That’s why we have added a random hand calculation test.
Random hand calculation testing
Hands Number: 200000
This test calculates 200000 random 7-card hands. The table above shows the number of generated hands in percentage and numerical ratios. For example, SET has appeared 9609 times in the test in 4.8045% of cases.
This algorithm has helped us a lot: comparing the test results with the probability of a poker hand occurrence, we found and fixed a bug. The bug appeared because we neglected special poker rules that are commonly known to all experienced players.
If you experience any problem using this algorithm, feel free to ask. Since social network games and other applications with a server-side are our team specialty, we’ll be glad to help.