You may be familiar with the common tools for load testing websites such as Apache’s ab, Siege, JMeter etc… The trouble when running benchmarks from your machine is that all requests come from a single source IP address which isn’t efficient enough for testing things like load balancing. Many load balancers, such as AWS’s Elastic Load Balancers, will send the requests to the same balanced node (in a short period of time), making it difficult to check that you’re achieving Round Robin load balancing, with a fairly even number of requests served on all your balanced nodes. So we need a tool that will distribute the load testing.
Enter bees with machine guns…
Bees with machine guns is “A utility for arming (creating) many bees (micro EC2 instances) to attack (load test) targets (web applications)”.
In other words, from a couple of commands only, you simulate traffic originating from several different sources to hit the target. Each source is a “bee” which is an EC2 micro instance, which will load test the target using Apache’s ab. But because we are launching multiple “bees”, we should be able to see proper load balancing thanks to the different source IPs of the bees.
Installation
Install the python package using pip:
1 |
sudo pip install beeswithmachineguns |
Configuration
Bees with machine guns uses boto to communicate with EC2, configure your ~/.boto file with your AWS credentials
and set your region:
1 2 3 4 5 6 |
[Credentials] aws_access_key_id=<YOUR-ACCESS-KEY> aws_secret_access_key=<YOUR-SECRET KEY> [Boto] ec2_region_name = ap-southeast-2 ec2_region_endpoint = ec2.ap-southeast-2.amazonaws.com |
Ensure you have a security group in EC2 that allow ssh port 22 incoming.
Choose an AMI which is available in your chosen region and which has Apache’s ab tool installed (or you can install it manually in 1 command which I’ll show how to).
Prepare bees
1 |
bees up -s 4 -g bees --key=<YOUR-PRIVATE-KEY> --i=ami-04ea7a3e --zone=ap-southeast-2a --login=ubuntu |
- -s for the number of bees/instances to launch
- -g the name of the security group
- –key the name of your AWS private ssh keypair
- –i the AMI
- –zone the availability zone where to launch the micro instances
- –login the default username the AMI uses for ssh (ubuntu for ubuntu AMI)
1 2 3 4 5 6 7 8 9 10 |
Connecting to the hive. Attempting to call up 4 bees. Waiting for bees to load their machine guns... . . . Bee i-xxxxxxxx is ready for the attack. Bee i-xxxxxxxx is ready for the attack. Bee i-xxxxxxxx is ready for the attack. Bee i-xxxxxxxx is ready for the attack. |
Wait for a couple of minutes until the bees have loaded their guns, meaning the ec2 instances are ready.
Installing ab
If the AMI doesn’t have Apache’s ab tool installed, you can remotely install it. First gather all the public IPs of the bees:
1 |
bees report |
Install cluster ssh and execute the installation of apache2-utils on all bees IP addresses:
1 2 |
sudo apt-get install clusterssh cssh --username=ubuntu -a 'sudo apt-get install apache2-utils -y' xx.xx.xx.xx xx.xx.xx.xx xx.xx.xx.xx xx.xx.xx.xx |
Bees attack
Now we’re ready to start the load testing by instructing the bees to hit the target.
Here we’re going to instruct the hive to send 10,000 requests to the -u target URL performing 100 concurrent requests:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
bees attack -n 10000 -c 100 -u http://<YOUR-TARGET-URL> Read 4 bees from the roster. Connecting to the hive. Assembling bees. Each of 4 bees will fire 2500 rounds, 25 at a time. Stinging URL so it will be cached for the attack. Organizing the swarm. Bee 0 is joining the swarm. Bee 1 is joining the swarm. Bee 2 is joining the swarm. Bee 3 is joining the swarm. Bee 3 is firing his machine gun. Bang bang! Bee 2 is firing his machine gun. Bang bang! Bee 0 is firing his machine gun. Bang bang! Bee 1 is firing his machine gun. Bang bang! Bee 3 is out of ammo. Bee 2 is out of ammo. Bee 0 is out of ammo. Bee 1 is out of ammo. Offensive complete. Complete requests: 10000 Requests per second: 136.460000 [#/sec] (mean) Time per request: 58.891500 [ms] (mean) 50% response time: 60.000000 [ms] (mean) 90% response time: 79.750000 [ms] (mean) Mission Assessment: Target crushed bee offensive. The swarm is awaiting new orders. |
Note: the target URL must be a static path ending with a /
Bees down
Once you are done with the load testing, remember to terminate your ec2 instances by issuing:
1 |
bees down |
Conclusion
Bees with machine guns is a cheap quick and easy way for distributed load testing.
Beware that bees with machine guns can be a distributed denial of service attack, so ensure the target URL is yours or you could get into serious trouble!