secret
Last active

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 combination of instructions and scripts from Eric Hankland and Anthony F. Voellm. You are free to reuse the code snippets. Keywords: GCE, GCLB, GCS, Google Compute Engine, Google Cloud Storage, Load Balancer

  • Download Gist
GCLB1000000
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 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482
***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

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.