Call the shell code of the AB command repeatedly and the Java code that organizes the AB results

Source: Internet
Author: User

First of all, the problem arises from the background, because to do stress testing, frequent use of the AB command, need to test a lot of items, each test to do more than 10 times, Test finished also to draw test results curve, and because the company intranet is not stable, test 10 times can not find an accurate value, so can only be tested when others work. But the problem is, once the server has changed the configuration, it is necessary to do all the tests again, and can only be measured at night, and can only be measured at night, and can only be measured at night ... The important thing to say three times. So I thought, what about the night Test, the bald head? So the day to write scripts, run at night, the morning to see the results, do a graph.

The AB command is a good site for stress testing tools,

Under Mac, see Help for Man AB

Under Linux, view the Help for AB--help

A simple and practical way to

Ab-n 10000-c 1 ' http://172.20.15.73:8080/sqltest/csp!cspexecute.ies '

n is the number of times, C is the concurrency number

Note that if the URL has parameters, you need to use single quotation marks ' wrapped, specific reasons to see the shell tutorial

The script is divided into two parts: the shell code, the call to the AB command, and the Java code to process the return result. (Ordinarily, I should write a part with JS to draw a picture or something, but lazy, and so on to add it)


The directory results for the script are as follows

Macbook:speedtest in$ Ls-r

Javatest speedtest.sh


./javatest:

Selecttext.class Selecttext.java


The first part, Shell code


#!/bin/sh
#产生数组
Makearray () {
Tomcatarray= (
"Http://172.20.15.73/csp!"
"Http://172.20.15.73:8080/sqltest/csp!"
)
TOMCAT=${TOMCATARRAY[$1]}
Modearray= (
' Ab-n 5000-c 1 '
' Ab-n 10000-c 1000 '
)
Linkarray= (
"Cspexecute.ies"
"Cspjson.ies"
"Cspgetuser.ies?id=8"
"Cspupdateuser.ies?id=8"
"Jdbceruptgetuser.ies?id=8"
"Jdbceruptupdateuser.ies?id=8"
)
}


#根据当前时间产生文件夹来保存测试结果
Prodir () {
datearray= (' Date ')

Dirname=./result/${datearray[1]}${datearray[2]}_${datearray[4]}_$1
Mkdir-p $dirName
}


#主测试函数
Dotest () {
Makearray $;
Prodir $;
For link in ${linkarray[@]}
Do
{
Local Textname=${dirname}/${link}.txt
Echo $textName;
For ((j=0;j<${#modeArray [@]};j++))
Do
{
temstring1= "===================== Test ${modearray[${j}]}--${link}==========================="
echo "${temstring1}\n" >> $textName
For ((i=1;i<11;i++));d o
{
Temstring2= "===================== ${i} times ==========================="
echo "$temString 1 \ $temString 2 \ n"
#temString3 = ""
temstring3= ' ${modearray[${j}]}${tomcat}${link} '
echo "$temString 3"
echo "$temString 2 \ $temString 3" >> $textName
Sleep 10
}
Done
}
Done
# After each connection test serial and concurrency, the access speed in its results is extracted and put into the Simpleresult.text
Java javatest/selecttext $textName $dirName/simpleresult.txt
}
Done
}


if [$#! = 1]
Then
echo "script is used Speedtest NUMBER0"
echo "NUMBER0 has a value of 0 is the default configuration of tomcat,1 is 1000 threads of Tomcat"
echo "NUMBER0 value is set to write AB's link for itself when the default loop is 10 times"
Else
# If the result folder does not exist, create a new result folder to hold the test results
# File= "./result"
# if [!-e $file]
# Then
# mkdir $file
# Fi


# If Selecttext.class does not exist, compile Selecttext.java
# File= "./java/selecttext.class"
#
# if [!-e $file]
# Then
# Javac Selecttext.java
# Fi


# Execute main test function
Dotest $;
Fi

Here are some of the problems encountered during execution, often encounteredoperation timed outThis question:

Apr_socket_recv:operation timed out (60)

This is apachebench, Version 2.3 < $Revision: 1663405 $>

Copyright 1996 Adam Twiss, Zeus technology LTD, http://www.zeustech.net/

Licensed to the Apache software Foundation, http://www.apache.org/

However, when the AB command is executed separately, it has not been encountered, so the single test time-n 10000 is changed to-N 5000

Online check, no results, self-righteous connection timeout, the results add the-s 120 parameter, still error. Maybe the reason for the Mac's ox system. Wait for the test on CentOS to add.

The test ran on CentOS for two days without reporting operation timed out (60) this error. Mac reported wrong, should be ox system is the reason.



Part Two Java code

Package javatest;


Import Java.io.BufferedReader;
Import Java.io.File;
Import Java.io.FileInputStream;
Import java.io.FileNotFoundException;
Import java.io.IOException;
Import Java.io.InputStreamReader;
Import Java.io.RandomAccessFile;


public class SelectText {
public static void Main (string[] args) throws IOException {

if (args.length!=2) {
SYSTEM.OUT.PRINTLN ("Please input parameters: Java selecttext input path output path");
Return
}
File InFile = new file (Args[0]);
BufferedReader in = null;
try {
FileInputStream instream = new FileInputStream (inFile);
in = new BufferedReader (new InputStreamReader (instream));
Randomaccessfile randomfile = new Randomaccessfile (args[1], "RW");
Long filelength = Randomfile.length ();
Randomfile.seek (filelength);
Randomfile.write ("Input file:" +args[0]+ "\ n"). GetBytes ());
String Line;
while (line = In.readline ()) = null) {
if (Line.contains ("Requests per Second:") | | Line.contains ("test")) {
System.out.println (line);
Randomfile.write ((line+ "\ n"). GetBytes ());
}
}
Randomfile.write ((args[0]+ "Test End \n\n\n"). GetBytes ());
Randomfile.close ();
Instream.close ();
System.out.println (args[0]+ "Conversion complete");
} catch (FileNotFoundException e) {
TODO auto-generated Catch block
E.printstacktrace ();
}
}
}


Run-time, execute./speedtest.sh 1


Call the shell code of the AB command repeatedly and the Java code that organizes the AB results

Related Article

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.