Last active
August 17, 2016 17:37
-
-
Save x-eye/8d2fc75f027b7e222284112787c8b13f to your computer and use it in GitHub Desktop.
Performance benchmark for https://review.openstack.org/#/c/309146/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Prerequisites: | |
# It runs on devstack using Mitaka release of OpenStack | |
# Some OS_ environment valiables are required, so run "# source openrc" before benchmarking | |
STACK_USER='stack' | |
CHECKOUT='git fetch git://git.openstack.org/openstack/keystone refs/changes/46/309146/14 && git checkout FETCH_HEAD' | |
AUTH_DATA='{"auth":{"identity":{"methods":["password"],"password":{"user":{"name":"'$OS_USERNAME'","domain":{"id":"default"},"password":"'$OS_PASSWORD'"}}},"scope":{"project":{"name":"'$OS_PROJECT_NAME'","domain":{"id":"default"}}}}}' | |
ITERATION_COUNT=42 | |
function token_issue { | |
curl -w "Time-Total: %{time_total}\\n" -o /dev/null -D - -s -X POST http://localhost/identity/v3/auth/tokens -H "Content-Type: application/json" -d $AUTH_DATA | |
} | |
function validate_token { | |
curl -w "Time-Total: %{time_total}\\n" -o /dev/null -D - -s -X GET http://localhost/identity/v3/auth/tokens -H "Content-Type: application/json" -H "X-Auth-Token: $1" -H "X-Subject-Token: $1" | |
} | |
function benchmark { | |
local ISSUE_TIME=0 | |
local VALIDATION_TIME=0 | |
local TOKEN="undefined" | |
for i in `seq 1 $ITERATION_COUNT` | |
do | |
while read -r key value | |
do | |
if [ "$key" == "X-Subject-Token:" ] | |
then | |
TOKEN=`echo $value | tr -d "\r\n"` | |
fi | |
if [ "$key" == "Time-Total:" ] | |
then | |
ISSUE_TIME=`echo $ISSUE_TIME + $value | bc -l` | |
fi | |
done < <(token_issue) | |
# echo "Token: $TOKEN" | |
# echo "Issue time accumulated: $ISSUE_TIME" | |
while read -r key value | |
do | |
value=`echo $value | tr -d '\r\n'` | |
if [ "$key" == "HTTP/1.1" ] && [ "$value" != "200 OK" ] | |
then | |
echo "Token validation failed, exiting..." | |
exit 1 | |
fi | |
if [ "$key" == "Time-Total:" ] | |
then | |
VALIDATION_TIME=`echo $VALIDATION_TIME + $value | bc -l` | |
fi | |
done < <(validate_token $TOKEN) | |
# echo "Validation time acucmulated: $VALIDATION_TIME" | |
done | |
echo "Average issue time" | |
echo $ISSUE_TIME / $ITERATION_COUNT | bc -l | |
echo "Average validation time" | |
echo $VALIDATION_TIME / $ITERATION_COUNT | bc -l | |
} | |
echo "Diving into keystone source directory" | |
cd /opt/stack/keystone/ | |
echo "Checking out commit before the change" | |
su $STACK_USER -c "$CHECKOUT"^ #&> /dev/null | |
su $STACK_USER -c "git log -n 1" | |
service apache2 graceful | |
echo ">>> Benchmarking token issue and validation without token pre-caching" | |
# Wake everything up | |
#benchmark > /dev/null | |
benchmark | |
echo | |
echo | |
echo "Checking out e8c02ef55bd4e562ad3896fbc88264304023c475 commit" | |
su $STACK_USER -c "$CHECKOUT" #&> /dev/null | |
su $STACK_USER -c "git log -n 1" | |
service apache2 graceful | |
echo ">>> Benchmarking token issue and validation with token pre-caching" | |
# Wake everything up | |
#benchmark > /dev/null | |
benchmark | |
echo "Returning to initial directory and exiting" | |
cd - |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment