Skip to content

Instantly share code, notes, and snippets.

@voellm voellm/GCLB1000000 Secret
Last active Aug 2, 2019

Embed
What would you like to do?
The following instructions walk you step-by-step in setting up a Google Compute Load Balancer benchmark that achieves 1,000,000 Requests Per Second. It is the code and step were used when writing a blog post for the Google Cloud Platform blog. You can find the Google Cloud Platform blog @ http://googlecloudplatform.blogspot.com/ This GIST is a c…
***NOTE --- This has been updated since the 1M RPS blog post to run on V1 of the GCE API
The scripts below are are broken up into:
1. Web Server In-Guest Startup Script used to create the Web Server Image.
Called webgueststartup.sh
2. Launch the Web Server machines using the previously created image.
Called webprovision.bash
3. Load Generator In-Guest Startup Script.
Called loadgengueststartup.sh
4. Launch the Load Generator machines using the Load Generator In-Guest Startup Script.
Called loadgen.bash
5. Process the Apache logs to determine the Request & Response Throughput.
Called computerps.py
Instructions on how to use the scripts and run the benchmark:
1. Create a project directory where all the scripts will reside. You will be
running these scripts from that directory.
$ mkdir gclb1m
2. Set the environment variable YOURPROJECT to the Google Cloud project you
are going to use. Here is an example:
$ export YOURPROJECT=voellm
3. You will want to enable both GCE and GCS for YOURPROJECT
4. Install gcutil (Google Compute Engine command line tool). Make sure it is in
your path and you have set up authentication for the project you plan to use.
5. Install gsutil (Google Cloud Storage command line tool). Make sure it is in
your path and you have set up authentication for the project you plan to use.
6. Copy all the scripts using the names provided into your project directory.
Make sure they are editable (chmod 755 *). Here is how my project directory
looked:
$ ls gclb1m
computerps.py loadgen.bash loadgengueststartup.sh webgueststartup.sh webprobision.bash
7. Now you are ready to setup the Web Server Image. For this we are going to
create an instance using the Web Guest Startup script called “webprovision”.
We will also use this same instance to gather results at the end so leave it
running. When asked for an image to boot choose the latest Wheezy7 image. If
you want to understand why certain instructions below are executed to create
the image read more about Creating GCE images (https://developers.google.com/compute/docs/images)
on the Cloud Platform Site. One last detail is to change “gs://voellm” to
your Google Cloud Storage Bucket. If you don't have one you should create one
on the Cloud Console (http://cloud.google.com/console).
$ cd gclb1m
$ gcutil --project=$YOURPROJECT addinstance webprovision --zone=europe-west1-a --machine_type=n1-standard-1 --metadata_from_file=startup-script:webgueststartup.sh
<.... choose an image ....>
$ gcutil --project=$YOURPROJECT ssh webprovision
<.... you are now running in the guest! ....>
$ ps -eaf | grep apache
<.... if apache is running go to the next step otherwise check again ....>
$ exit
<.... leaving the guest ....>
8. Download curl_loader to your project directory. Then follow the steps below
to build curl_loader in the webprovision machine. We do this to make sure we
don't hit any library issues.
$ gcutil --project=$YOURPROJECT push webprovision curl-loader-0.56.tar.bz2 .
$ gcutil --project=$YOURPROJECT ssh webprovision
<.... you are now running in the guest! ....>
$ sudo apt-get install bzip2 -y
$ sudo apt-get install build-essential -y
$ sudo apt-get install libssl-dev -y
$ tar jxf curl-loader-0.56.tar.bz2
$ cd curl-loader-0.56
$ make debug=0 optimize=1
$ sudo make install
$ cp curl-loader ..
$ exit
<.... leaving the guest ....>
9. Now you are ready to create the image for the websever and loadgen VM's.
$ gcutil --project=$YOURPROJECT ssh webprovision
<.... you are now running in the guest! ....>
$ sudo gcimagebundle -d /dev/sda -o /tmp/ --log_file=/tmp/abc.log
<.... this takes a couple of minutes ....>
$ cd /tmp
$ ls # I am looking for a file with <numbers>.image.tar.gz
$ exit
<.... leaving the guest ....>
$ gcutil --project=$YOURPROJECT pull webprovision /tmp/<numbers>.image.tar.gz .
$ gsutil mb gs://voellm
$ gsutil cp <numbers>.image.tar.gz gs://voellm
$ gcutil --project=$YOURPROJECT addimage gclb1mimage gs://voellm/<numbers>.image.tar.gz
<.... you will be prompted for a kernel. Pick a latest with no-conn-track in the name ....>
10. Now you are ready to kick off your Web Server VMs
$ chmod 755 webprovision.bash
$ ./webprovision.bash start
11. Now you are ready to kick off the load generator. This is fun!
$ chmod 755 loadgen.bash
$ ./loadgen.bash start
12. As a sanity check you can make sure all the VMs are running.
$ gcutil --project=$YOURPROJECT listinstances
+--------------+----------------+---------+----------------+----------------+
| name | zone | status | network-ip | external-ip |
+--------------+----------------+---------+----------------+----------------+
| gw0 | europe-west1-a | RUNNING | 10.164.190.193 | |
+--------------+----------------+---------+----------------+----------------+
| gw1 | europe-west1-a | RUNNING | 10.206.175.123 | |
+--------------+----------------+---------+----------------+----------------+
| gw10 | europe-west1-a | RUNNING | 10.253.142.96 | |
+--------------+----------------+---------+----------------+----------------+
| gw2 | europe-west1-a | RUNNING | 10.203.55.215 | |
+--------------+----------------+---------+----------------+----------------+
| gw3 | europe-west1-a | RUNNING | 10.77.95.15 | |
+--------------+----------------+---------+----------------+----------------+
| gw4 | europe-west1-a | RUNNING | 10.15.188.148 | |
+--------------+----------------+---------+----------------+----------------+
| gw5 | europe-west1-a | RUNNING | 10.60.188.93 | |
+--------------+----------------+---------+----------------+----------------+
| gw6 | europe-west1-a | RUNNING | 10.74.212.116 | |
+--------------+----------------+---------+----------------+----------------+
| gw7 | europe-west1-a | RUNNING | 10.122.236.87 | |
+--------------+----------------+---------+----------------+----------------+
| gw8 | europe-west1-a | RUNNING | 10.3.243.104 | |
+--------------+----------------+---------+----------------+----------------+
| gw9 | europe-west1-a | RUNNING | 10.173.52.23 | |
+--------------+----------------+---------+----------------+----------------+
| lg0 | europe-west1-a | RUNNING | 10.117.68.136 | 8.34.221.4 |
+--------------+----------------+---------+----------------+----------------+
| lg1 | europe-west1-a | RUNNING | 10.73.139.229 | 8.34.221.11 |
+--------------+----------------+---------+----------------+----------------+
| lg2 | europe-west1-a | RUNNING | 10.98.64.173 | 8.34.221.16 |
+--------------+----------------+---------+----------------+----------------+
| lg3 | europe-west1-a | RUNNING | 10.3.142.86 | 8.34.211.6 |
+--------------+----------------+---------+----------------+----------------+
| lg4 | europe-west1-a | RUNNING | 10.78.35.79 | 8.34.222.196 |
+--------------+----------------+---------+----------------+----------------+
| webprovision | europe-west1-a | RUNNING | 10.184.150.3 | 8.34.222.70 |
+--------------+----------------+---------+----------------+----------------+
13. Once this has run for a while you can stop it
$ ./loadgen.bash stop
14. Now we we need to capture all the result files to check the RPS achieved.
The first step is to get the public ssh key into the guest. Then we copy
the files from all the web servers. Then we copy them locally to be
processed. We have to use webprovision VM as an intermediary because the
web servers were started without a public IP address.
$ gcutil --project=$YOURPROJECT push webprovision ~/.ssh/google_compute_engine .
$ gcutil --project=$YOURPROJECT ssh webprovision
<.... you are now running in the guest! ....>
$ chmod 600 google_compute_engine
$ mv google_compute_engine ~/.ssh/
$ for i in {0..199}; do scp -i ~/.ssh/google_compute_engine -o CheckHostIP=no -o StrictHostKeyChecking=no $USERNAME@gw$i:/var/log/apache2/access.log access$i.log; done
$ exit
<.... leaving the guest ....>
$ mkdir result1
$ gcutil --project=$YOURPROJECT pull webprovision access* result1
15. Now that the results are local you can process them to get the final
result.csv you can load into your favorite spreadsheet. The result.csv
file has “<time>,<requests per second>” one per line for all time
intervals computed.
$ cd result1
$ ../computerps.py > result.csv
$ cd ..
16. Delete your web server and webprovision instance.
$ ./webprovision.bash stop
$ gcutil --project=$YOURPROJECT deleteinstance webprovision
########################################################
## 1. Web Server Guest Startup Script - webgueststartup.sh
########################################################
#!/bin/sh
apt-get -y update
apt-get -y install apache2
rm /etc/apache2/sites-available/default-ssl
echo 'LogFormat "%{%s}t" time' >> /etc/apache2/apache2.conf
echo '<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /var/www
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log time
</VirtualHost>' > /etc/apache2/sites-enabled/000-default
echo '
<IfModule mpm_worker_module>
StartServers 2
MinSpareThreads 25
MaxSpareThreads 75
ThreadLimit 64
ThreadsPerChild 25
MaxClients 400
MaxRequestsPerChild 0
</IfModule>
' >> /etc/apache2/apache2.conf
/etc/init.d/apache2 restart
dd if=/dev/zero of=/var/www/tiny bs=1 count=0 seek=1
echo 'net.core.wmem_max=12582912' >> /etc/sysctl.conf
echo 'net.core.rmem_max=12582912' >> /etc/sysctl.conf
echo 'net.ipv4.tcp_rmem= 10240 87380 12582912' >> /etc/sysctl.conf
echo 'net.ipv4.tcp_wmem= 10240 87380 12582912' >> /etc/sysctl.conf
echo 'net.ipv4.tcp_window_scaling = 1' >> /etc/sysctl.conf
echo 'net.ipv4.tcp_timestamps = 1' >> /etc/sysctl.conf
echo 'net.ipv4.tcp_sack = 1' >> /etc/sysctl.conf
echo 'net.core.netdev_max_backlog = 5000' >> /etc/sysctl.conf
sysctl -p
########################################################
## 2. Launch the Web Servers - webprovision.bash
########################################################
#! /bin/bash
# Usage webprovision.bash [start | stop]
# start means to create the web serving environment, LB, etc
# stop mean to teardown the web serving environment. LB, etc
/bin/date
STARTUP_SCRIPT=lb_startup.sh
MACHINE_TYPE=n1-standard-1
PROJECT_ID=$YOURPROJECT
IMAGE=gclb1mimage
INSTANCE_NAMES1=()
INSTANCE_NAMES2=()
INSTANCE_NAMES3=()
INSTANCE_NAMES4=()
for i in {0..49}
do
INSTANCE_NAMES1=("${INSTANCE_NAMES1[@]}" "europe-west1-a/instances/gw$i")
done
for i in {50..99}
do
INSTANCE_NAMES2=("${INSTANCE_NAMES2[@]}" "europe-west1-a/instances/gw$i")
done
for i in {100..149}
do
INSTANCE_NAMES3=("${INSTANCE_NAMES3[@]}" "europe-west1-a/instances/gw$i")
done
for i in {150..199}
do
INSTANCE_NAMES4=("${INSTANCE_NAMES4[@]}" "europe-west1-a/instances/gw$i")
done
INSTANCE_NAMES_SS1=$( IFS=$' '; echo "${INSTANCE_NAMES1[*]}" )
INSTANCE_NAMES_CS1=$( IFS=$','; echo "${INSTANCE_NAMES1[*]}" )
INSTANCE_NAMES_SS2=$( IFS=$' '; echo "${INSTANCE_NAMES2[*]}" )
INSTANCE_NAMES_CS2=$( IFS=$','; echo "${INSTANCE_NAMES2[*]}" )
INSTANCE_NAMES_SS3=$( IFS=$' '; echo "${INSTANCE_NAMES3[*]}" )
INSTANCE_NAMES_CS3=$( IFS=$','; echo "${INSTANCE_NAMES3[*]}" )
INSTANCE_NAMES_SS4=$( IFS=$' '; echo "${INSTANCE_NAMES4[*]}" )
INSTANCE_NAMES_CS4=$( IFS=$','; echo "${INSTANCE_NAMES4[*]}" )
ZONE="europe-west1-a"
REGION="europe-west1"
if [ "$1" == "start" ]
then
# Create the LB
time gcutil --project=$PROJECT_ID addfirewall gw-firewall --allowed=tcp:80
time gcutil --project=$PROJECT_ID addtargetpool gw-pool --region=$REGION
time gcutil --project=$PROJECT_ID addforwardingrule gw-rule --region=$REGION --port_range=80 --target=gw-pool
# Boot the machines
time gcutil --project=$PROJECT_ID addinstance $INSTANCE_NAMES_SS1 --image=$IMAGE --zone=$ZONE --machine_type=$MACHINE_TYPE --external_ip_address=none &
time gcutil --project=$PROJECT_ID addinstance $INSTANCE_NAMES_SS2 --image=$IMAGE --zone=$ZONE --machine_type=$MACHINE_TYPE --external_ip_address=none &
time gcutil --project=$PROJECT_ID addinstance $INSTANCE_NAMES_SS3 --image=$IMAGE --zone=$ZONE --machine_type=$MACHINE_TYPE --external_ip_address=none &
time gcutil --project=$PROJECT_ID addinstance $INSTANCE_NAMES_SS4 --image=$IMAGE --zone=$ZONE --machine_type=$MACHINE_TYPE --external_ip_address=none
# Add the machine to the LB
time gcutil --project=$PROJECT_ID addtargetpoolinstance gw-pool --region=$REGION --instances=$INSTANCE_NAMES_CS1
time gcutil --project=$PROJECT_ID addtargetpoolinstance gw-pool --region=$REGION --instances=$INSTANCE_NAMES_CS2
time gcutil --project=$PROJECT_ID addtargetpoolinstance gw-pool --region=$REGION --instances=$INSTANCE_NAMES_CS3
time gcutil --project=$PROJECT_ID addtargetpoolinstance gw-pool --region=$REGION --instances=$INSTANCE_NAMES_CS4
else
if [ "$1" == "stop" ]
then
time gcutil --project=$PROJECT_ID deleteforwardingrule -f gw-rule --region=$REGION
time gcutil --project=$PROJECT_ID deletetargetpool -f gw-pool --region=$REGION
time gcutil --project=$PROJECT_ID deleteinstance -f --delete_boot_pd $INSTANCE_NAMES_SS1 --zone=$ZONE
time gcutil --project=$PROJECT_ID deleteinstance -f --delete_boot_pd $INSTANCE_NAMES_SS2 --zone=$ZONE
time gcutil --project=$PROJECT_ID deleteinstance -f --delete_boot_pd $INSTANCE_NAMES_SS3 --zone=$ZONE
time gcutil --project=$PROJECT_ID deleteinstance -f --delete_boot_pd $INSTANCE_NAMES_SS4 --zone=$ZONE
time gcutil --project=$PROJECT_ID deletefirewall -f gw-firewall
else
echo "$0 [stop | start]"
fi
fi
/bin/date
########################################################
## 3. Load Generator In-Guest Startup Script - loadgengueststartup.sh
########################################################
#!/bin/sh
IP=`/sbin/ifconfig eth0 | grep 'inet addr:' | cut -d: -f2 | awk '{ print $1}'`
echo "BATCH_NAME= test
CLIENTS_NUM_MAX=1000
CLIENTS_NUM_START=1000
CLIENTS_RAMPUP_INC=10
NETMASK=32
INTERFACE =eth0
IP_ADDR_MIN=$IP
IP_ADDR_MAX=$IP
CYCLES_NUM= -1
URLS_NUM= 1
########### URLs SECTION #######################
# Change URL to be xxx.xxx.xxx.xxx/tiny where the x’s are the
# ip of the forwarding rule of the load balancer
URL=FORWARDINGIP
URL_SHORT_NAME="tiny"
REQUEST_TYPE=GET
TIMER_URL_COMPLETION = 0
TIMER_AFTER_URL_SLEEP = 0" > /tmp/test.conf
########################################################
## 4. Launch The Load Generators - loadgen.bash
########################################################
#! /bin/bash
# Usage loadgen.bash [start | stop]
# start the load generators instances
# stop the load generator instances
LG_SCRIPT=loadgengueststartup.sh
PROJECT_ID=$YOURPROJECT
LG_MACHINE_TYPE=n1-standard-4
IMAGE=gclb1mimage
ZONE="europe-west1-a"
REGION="europe-west1"
LG_NAMES=()
for i in {0..63}
do
LG_NAMES=("${LG_NAMES[@]}" "lg$i")
done
LG_NAMES_SS=$( IFS=$' '; echo "${LG_NAMES[*]}" )
LG_NAMES_CS=$( IFS=$','; echo "${LG_NAMES[*]}" )
if [ "$1" == "start" ]
then
export IP=`gcutil --project=$YOURPROJECT getforwardingrule gw-rule | awk -F '|' '{if (index($2, "ip ") != 0) print $3;}'`
sed "s/FORWARDINGIP/$IP/g" $LG_SCRIPT > temp.sh
gcutil --project=$PROJECT_ID addinstance $LG_NAMES_SS --image=$IMAGE --zone=$ZONE --machine_type=$LG_MACHINE_TYPE --metadata_from_file=startup-script:temp.sh
# Compile curl-loader v.56 with debug off and optimize on and distribute the binary
# to each load generator
# Start curl-loader on each load generator (test.conf should point to wherever the startup
# script put the conf file)
for i in {0..63}
do
gcutil --project=$PROJECT_ID ssh ${LG_NAMES[i]} "sh -c 'nohup sudo ./curl-loader -w -r -t 16 -f /tmp/test.conf > nohup.out 2>&1 &'" &
done
else
gcutil --project=$PROJECT_ID deleteinstance -f --delete_boot_pd $LG_NAMES_SS --zone=$ZONE
fi
########################################################
## 5. Process the Apache logs to determine RPS - computerps.py
########################################################
#!/usr/bin/env python
import glob
file_names = glob.glob("*.log")
files = []
time = float("inf")
next_lines = dict()
for f in file_names:
log = open(f, 'r')
files.append(log)
next_lines[log] = log.readline()
time = min(time, int(next_lines[log]))
linesleft = True
while linesleft:
total = 0
for log in files:
while len(next_lines[log]) != 0 and time > int(next_lines[log]):
next_lines[log] = log.readline()
if len(next_lines[log]) == 0 or time < int(next_lines[log]):
continue
count = 0
next_line = log.readline()
while len(next_line) != 0 and int(next_lines[log]) >= int(next_line):
count += 1
next_line = log.readline()
next_lines[log] = next_line
total += count
if total != 0:
print str(time) + "," + str(total)
if total != 0:
time += 1
else:
next_time = float("inf")
for line in next_lines.values():
if len(line) != 0:
next_time = min(next_time, int(line))
time = next_time
linesleft = False
for line in next_lines.values():
if line:
linesleft = True
break
@kikitux

This comment has been minimized.

Copy link

commented Mar 25, 2016

the for loop seems not necesary:

INSTANCE_NAMES1=(europe-west1-a/instances/gw{1..49})
INSTANCE_NAMES2=(europe-west1-a/instances/gw{50..99})
INSTANCE_NAMES3=(europe-west1-a/instances/gw{100..149})
INSTANCE_NAMES4=(europe-west1-a/instances/gw{150..199})
LG_NAMES=(lg{0..63})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.