Wrk+fabric for cluster deployment and pressure measurement

Source: Internet
Author: User
Tags bz2 chmod gmp lua openssl time interval touch python script
First, WRK deployment

1 , deploy the control machine

A machine is required to install fabric and wrk as a control machine.

(1) Install fabric

The first step: after the Fabric.rar decompression, the entire directory uploaded to the control machine/home directory

Install package:

Cffi-1.9.1.tar.gz
Cryptography-1.6.tar.gz
Ecdsa-0.13.tar.gz
Enum34-1.1.6.tar.gz
Fabric-1.12.0.tar.gz
gmp-6.0.0a.tar.bz2
Idna-2.1.tar.gz
install.sh
Ipaddress-1.0.17.tar.gz
libffi-devel-3.0.5-3.2.el6.x86_64.rpm
Openssl-1.0.2.tar.gz
Paramiko-1.15.2.tar.gz
Pyasn1-0.1.9.tar.gz
Pycparser-2.17.tar.gz
Pycrypto-2.6.1.tar.gz
Python-2.7.11.tgz
Setuptools-30.2.0.tar.gz
Six-1.10.0.tar.gz
zlib-1.2.3-29.el6.x86_64.rpm
zlib-devel-1.2.3-29.el6.x86_64.rpm

Auto-Install script install.sh

#!/bin/bash
#将python环境升级到2.7.11
RPM-IVH zlib-1.2.3-29.el6.x86_64.rpm
RPM-IVH zlib-devel-1.2.3-29.el6.x86_64.rpm
TAR-XVF python-2.7.11.tgz
CD Python-2.7.11
./configure
Make all
Make install
Make clean
Make Distclean
Mv/usr/bin/python/usr/bin/python_old
Ln-s/usr/local/bin/python2.7/usr/bin/python
Cd..


#安装fabric模块
TAR-XVF gmp-6.0.0a.tar.bz2
CD gmp-6.0.0
./configure
Make
Make check
Make install
Cd..
TAR-XVF setuptools-30.2.0.tar.gz
CD setuptools-30.2.0
Python setup.py Build
Python setup.py Install
Cd..
TAR-XVF pycrypto-2.6.1.tar.gz
CD pycrypto-2.6.1
Export Ac_cv_func_malloc_0_nonnull=yes
Python setup.py Build
Python setup.py Install
Cd..
TAR-XVF pyasn1-0.1.9.tar.gz
CD pyasn1-0.1.9
Python setup.py Build
Python setup.py Install
Cd..
RPM-IVH libffi-devel-3.0.5-3.2.el6.x86_64.rpm
TAR-XVF pycparser-2.17.tar.gz
CD pycparser-2.17
Python setup.py Build
Python setup.py Install
Cd..
TAR-XVF cffi-1.9.1.tar.gz
CD cffi-1.9.1
Python setup.py Build
Python setup.py Install
Cd..
TAR-XVF openssl-1.0.2.tar.gz
CD openssl-1.0.2
./config--prefix=/usr/local/openssl-1.0.2 Shared zlib-dynamic Enable-camellia
Make && make install
Ln-s/usr/lib64/libssl.so.1.0.1e/usr/lib64/libssl.so
Ln-s/usr/lib64/libcrypto.so.1.0.1e/usr/lib64/libcrypto.so
Cd..
TAR-XVF ipaddress-1.0.17.tar.gz
CD ipaddress-1.0.17
Python setup.py Build
Python setup.py Install
Cd..
TAR-XVF enum34-1.1.6.tar.gz
CD enum34-1.1.6
Python setup.py Build
Python setup.py Install
Cd..
TAR-XVF six-1.10.0.tar.gz
CD six-1.10.0
Python setup.py Build
Python setup.py Install
Cd..
TAR-XVF idna-2.1.tar.gz
CD idna-2.1
Python setup.py Build
Python setup.py Install
Cd..
TAR-XVF cryptography-1.6.tar.gz
CD cryptography-1.6
Export C_include_path=/usr/local/openssl-1.0.2/include
Export Cplus_include_path=/usr/local/openssl-1.0.2/include
Python setup.py Build
Python setup.py Install
Cd..
TAR-XVF ecdsa-0.13.tar.gz
CD ecdsa-0.13
Python setup.py Build
Python setup.py Install
Cd..
TAR-XVF paramiko-1.15.2.tar.gz
CD paramiko-1.15.2
Python setup.py Build
Python setup.py Install
Cd..
TAR-XVF fabric-1.12.0.tar.gz
CD Fabric-1.12.0
Python setup.py Build
Python setup.py Install
Cd..

Step Two: Enter the/home/fabric directory, assign execution permissions to the install.sh file, and then execute

Cd/home/fabric

chmod u+x install.sh

./install.sh

After the execution of the script, see if the error is correct, and then execute the script if it is corrected according to the wrong information.

Step Three: Verify that fabric is installed successfully

Python-c "from FABRIC.API import *; Print Env.version "

Execute the above command on the control machine, display the version indicating that the installation was successful

If error: ERROR:root:code for hash MD5 is not found

Execute the following command

Python

>>>import_hashlib

(2) Installation wrk

Step One: upload the wrk-master.zip to the/home directory of the controller and perform the decompression command

Cd/home

Unzipwrk-master.zip

Step Two: enter the/home/wrk-master directory and execute the installation command

Cdwrk-master

Make

After the compilation completes, the WRK binaries are generated in the/home/wrk-master directory.

Step Three: upload the Delayx.lua file to the/home/wrk-master/scripts directory of the control machine

Delayx.lua file

function delay ()
Return Math.random (${thinktime}, ${thinktime})
End

Fourth step: upload controller.py, readhost.py, clienthosts.txt three files to the/home directory of the control machine

controller.py file

#!/usr/bin/python
#-*-Coding:utf-8-*-


From readhost Import *
From FABRIC.API Import *
From fabric.colors Import *
From fabric.context_managers Import *
From fabric.state Import env
Import re
Import OS
Import Sys
Import datetime
#run Test Entrance,defin necessary parameter
Def runtest ():
Test_name= "test_001" #test case name
Threads=4 #numbers of thread of every client host
Connections=4 #numbers of connection of every client host
durations=10 #time of test case running
thinktime=2000 #the time interval between requests
Url= "http://10.41.150.52:8082/job/tcep/" #request URL


DT = Datetime.datetime.now ()
Res_file = "/home/test_result/%s_%s.txt"% (TEST_NAME,DT)
Res_file = Res_file.replace ("", "_")
If Os.path.exists ("/home/test_result"):
With settings (hide (' warnings ', ' running ', ' stdout ', ' stderr '), warn_only=true):
Local (' Touch%s '%res_file)
Else
With settings (hide (' warnings ', ' running ', ' stdout ', ' stderr '), warn_only=true):
Local ("Mkdir/home/test_result&&touch%s"%res_file)
With settings (hide (' warnings ', ' running ', ' stdout ', ' stderr '), warn_only=true):
Execute (runwrk,threads,connections,durations,url,test_name,thinktime,res_file)
With open (Res_file, ' R ') as F:
Counts = F.readlines ()
If counts:
LTC = COUNTLTC (Res_file)
TPS = Counttps (res_file)
IO = Countio (res_file)
Print yellow (' Total => [90Percent latancy:%s] [tps:%s] [io:%s] '% (Ltc,tps,io))
With settings (hide (' warnings ', ' running ', ' stdout ', ' stderr '), warn_only=true):
Local ("echo" Total => [90Percent latancy:%s] [tps:%s] [io:%s] ' >>%s '% (ltc,tps,io,res_file))
#get Client Host IP list
env.roledefs[' wrk '] = HostList
#get Client host password list
Env.passwords = Hostpswlist
#get result function
def getwrkresult (text):
P1 = '. +?90%\s+ (? P<latancy90>\d+\.? \d+\w+) '
P2 = ' requests/sec:\s+ (? P<tps>\d+\.? \d+) '
P3 = ' transfer/sec:\s+ (? P<tps_io>\d+\.? \d+\w+) '
ret = {}
M1 = Re.search (P1,text)
M2 = Re.search (p2,text)
M3 = Re.search (P3,text)
If M1:
ret[' latancy90 '] = M1.group ("Latancy90")
ret[' TPS '] = M2.group ("TPS")
ret[' io '] = M3.group ("Tps_io")
return ret
#deploy wrk to all client host
@roles ("wrk")
@parallel (pool_size=30)
Def deploywrk ():
With settings (hide (' warnings ', ' running '), warn_only=true):
Run ("Mkdir-p/home/wrk-master/scripts")
Put ("/home/wrk-master/wrk", "/home/wrk-master/")
Run ("chmod u+x/home/wrk-master/wrk")
Put ("/home/wrk-master/scripts/*", "/home/wrk-master/scripts/")

#begin to run wrk command in the all client host
@roles ("wrk")
@parallel
def runwrk (threads,connections,durations,url,test_name,thinktime,res_file):
If threads>connections:
Print red ("%s:number of connections must be >= threads"%env.host)
Return
If ThinkTime:
CMD = "./wrk-t{th}-c{con}-d{dur}s-t30s--script=./delay.lua--latency {test_url}". Format (th=threads,con=connections , Dur=durations,test_url=url)
Else
CMD = './wrk-t{th}-c{con}-d{dur}s-t30s--latency {test_url} '. Format (th=threads,con=connections,dur=durations,test_ Url=url)
Host_speed_type = List (Host_speed_type_define.keys ()) [List (Host_speed_type_define.values ()). Index (Env.host)]
ThinkTime = Speed_type_define[host_speed_type]

Wrkdir = '/home/wrk-master/'
With CD (WRKDIR):
Print Green ('%s:start testing with wrk ... '%env.host)
Run ("Export Thinktime=%d&&envsubst ' ${thinktime} ' <./scripts/delayx.lua >delay.lua"%thinktime)
Run (CMD + ">%s_%s.result"% (test_name,env.host))
Run ("Rm-f Delay.lua")
Wrk_ret = Getwrkresult (Run ("Cat%s_%s.result"% (test_name,env.host))
If Wrk_ret:
TMP = ' {wrkhost} => [90Percent latancy:{latancy}] [Tps:{tps}] [Io:{io}] [Url:{test_url}] '. Format (wrkhost = Env.host, Latancy = wrk_ret["latancy90"],tps = wrk_ret["TPS"],io = wrk_ret["io"],test_url = URL)
Local ("Echo '%s ' >>%s"% (Tmp,res_file))
Print yellow (' {wrkhost} => [90Percent latancy:{latancy}] [Tps:{tps}] [Io:{io}] [Url:{test_url}] '. Format (wrkhost = Env.host,latancy = wrk_ret["latancy90"],tps = wrk_ret["TPS"],io = wrk_ret["io"],test_url = URL))
Else
Print red ("%s:test result is empty!" %env.host)


#count 90Percent latancy Average
def COUNTLTC (resultfile):
With open (Resultfile, ' R ') as F:
Reslist = F.readlines ()
Reslist = [S[0] for S in [(Res.split (' latancy: ') [1].split ('] [TPS ')] for res in reslist]]
Total = 0
For reslist:
If Time.count (' Us '):
Total = total + float (time.split ('. ') [0]) /1000
Else
If Time.count (' Ms '):
Total = total + float (time.split (' Ms ') [0])
Else
Total = total + float (time.split (' m ') [0]) *1000
Return Str (Round (Total/len (reslist), 2)) + ' Ms '
#count Total TPS
def Counttps (resultfile):
With open (Resultfile, ' R ') as F:
Reslist = F.readlines ()
Reslist = [S[0] for S in [Res.split (' [TPS: '] [1].split ('] [IO ')] for res in reslist]]
Total = 0
For TPS in Reslist:
Total = total + float (TPs)
Return Total
#count Total IO
def countio (resultfile):
With open (Resultfile, ' R ') as F:
Reslist = F.readlines ()
Reslist = [S[0] for S in [Res.split (' [IO: ') [1].split ('] [URL ')] for res in reslist]]
Total = 0
CONTAINMB = False
For IO in reslist:
If Io.count (' MB '):
CONTAINMB = True
If CONTAINMB:
For IO in reslist:
If Io.count (' MB '):
Total = total + float (io.split (' MB ') [0])
Else
If Io.count (' KB '):
Total = total + float (io.split (' KB ') [0])/1024
Else
For IO in reslist:
If Io.count (' KB '):
Total = total + float (io.split (' KB ') [0])
If CONTAINMB:
Return Str (round (total,2)) + ' MB '
Else
Return Str (round (total,2)) + ' KB '

readhost.py file

#!/usr/bin/python
#-*-Coding:utf-8-*-
#read Client host IP list from ClientHost file
#format: [' root@10.41.150.177:22 ', ' root@10.41.139.175:22 ']
def gethostlist (hostfile):
With open (Hostfile, ' R ') as F:
IPList = F.readlines ()
IPList = [' root@ ' + s[0] + ': ' for S in [(Ip.split (' t ')] for IP in IPList]]
Return IPList

#read Client host password list from ClientHost file
#format: {' root@10.41.150.208:22 ': ' C3e#6jt (FB6PPJ ', ' root@10.41.139.175:22 ': ' Tnscp56m#nr2*k '}
def gethostpswlist (hostfile):
With open (Hostfile, ' R ') as F:
IPList = F.readlines ()
IPList = [(Ip.split (' t ')) for IP in IPList]
Psw_dic = {}
For S in IPList:
psw_dic[' root@ ' + s[0] + ': '] = S[1].strip ()
Return Psw_dic


HostList = Gethostlist ("Clienthosts.txt")
Hostpswlist = Gethostpswlist ("Clienthosts.txt")


if __name__ = = ' __main__ ':
Print HostList
Print Hostpswlist

Clienthosts.txt file

10.41.26.162 QEn68 (BMY$K7PW
10.41.26.164 rsf!qb7qgj7a!3

 

2 , deployment of pressure machine

Using more than one machine as a press, you can deploy WRK to all the presses using the already deployed control machine.

(1) Deployment of WRK tools

(This step is done once, and you need to do it again if you want to add a press)

The first step: remote Login to the control machine, into the/home directory

Step Two: Modify the Clienthosts.txt file, add the pressure machine IP address and the corresponding root login password, the format is as follows:

10.41.150.50 AWd (G8HW (QYs62

10.41.150.51 Viljbp858_h#yb

Note: 1, IP and password separated by tab

2, the last record do not wrap, that is, no blank lines

Step three: execute command fab-fcontroller.py deploywrk

Perform a command procedure to check for errors

Second, wrk cluster pressure test

1 , WRK tool test Framework Description

Use 1 machines as a control machine (deploy fabric, control other presses to execute WRK scripts in parallel, collect other press execution results and display test results in the controller), use multiple machines as machine pressure tester (deploy WRK tool, execute WRK command to send to server http/ HTTPS request), deploying the WRK tool on all stress testers or executing the WRK command is implemented through the control's Python script controller.py.

 

2 , performing cluster concurrency testing

The first step: remote Login to the control machine, into the/home directory

Step Two: Modify the controller.py script to modify the following parameters as needed:

Test_name= "test_001" test scenario name, you can customize

Threads=4 the number of start-up threads per press, preferably with the number of CPUs in the machine.

connections=1000 the number of connections that each press creates must be greater than or equal to the number of boot threads

durations=60 test script runs long, unit seconds

Thinktime= 2000 think time, time interval per request, Unit millisecond

Url= the address sent by the "https://www.test.com/" request


Step Three: start the cluster concurrency test, execute the command fab-f controller.py runtest

Execution process Monitoring whether there is an error

Fourth Step: Review the test results, after the completion of the control machine will print each press test results and the overall statistical results

Result format: Press machine IP => [90 response time][tps] [per second network IO] [test address] test results are also saved under the/home/test_result/directory, the file name format: Test Scene Name _ date _ minutes.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.