mirror of
https://github.com/pocoproject/poco.git
synced 2025-10-14 15:05:35 +02:00
submitted 1.2.0
This commit is contained in:
7
Net/samples/HTTPLoadTest/HTTPLoadTest.vmsbuild
Normal file
7
Net/samples/HTTPLoadTest/HTTPLoadTest.vmsbuild
Normal file
@@ -0,0 +1,7 @@
|
||||
#
|
||||
# HTTPLoadTest.vmsbuild
|
||||
#
|
||||
# $Id: //poco/1.2/Net/samples/HTTPLoadTest/HTTPLoadTest.vmsbuild#1 $
|
||||
#
|
||||
EXE=HTTPLoadTest
|
||||
HTTPLoadTest
|
145
Net/samples/HTTPLoadTest/HTTPLoadTest_vs71.vcproj
Normal file
145
Net/samples/HTTPLoadTest/HTTPLoadTest_vs71.vcproj
Normal file
@@ -0,0 +1,145 @@
|
||||
<?xml version="1.0" encoding="Windows-1252"?>
|
||||
<VisualStudioProject
|
||||
ProjectType="Visual C++"
|
||||
Version="7.10"
|
||||
Name="HTTPLoadTest"
|
||||
ProjectGUID="{455C9515-4914-49B6-93FB-C37242A6C21C}"
|
||||
Keyword="Win32Proj">
|
||||
<Platforms>
|
||||
<Platform
|
||||
Name="Win32"/>
|
||||
</Platforms>
|
||||
<Configurations>
|
||||
<Configuration
|
||||
Name="debug_shared|Win32"
|
||||
OutputDirectory="obj\debug_shared"
|
||||
IntermediateDirectory="obj\debug_shared"
|
||||
ConfigurationType="1"
|
||||
UseOfMFC="2"
|
||||
CharacterSet="2">
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="0"
|
||||
AdditionalIncludeDirectories=".\include;..\..\..\Foundation\include;..\..\..\XML\include;..\..\..\Net\include;..\..\..\Util\include"
|
||||
PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;POCO_DLL;WINVER=0x0500"
|
||||
MinimalRebuild="TRUE"
|
||||
BasicRuntimeChecks="3"
|
||||
RuntimeLibrary="3"
|
||||
BufferSecurityCheck="TRUE"
|
||||
TreatWChar_tAsBuiltInType="TRUE"
|
||||
ForceConformanceInForLoopScope="TRUE"
|
||||
RuntimeTypeInfo="TRUE"
|
||||
UsePrecompiledHeader="0"
|
||||
WarningLevel="3"
|
||||
Detect64BitPortabilityProblems="TRUE"
|
||||
DebugInformationFormat="4"/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
AdditionalDependencies="PocoFoundationd.lib PocoXMLd.lib PocoNetd.lib PocoUtild.lib"
|
||||
OutputFile="bin/HTTPLoadTestd.exe"
|
||||
LinkIncremental="2"
|
||||
AdditionalLibraryDirectories="..\..\..\lib"
|
||||
GenerateDebugInformation="TRUE"
|
||||
ProgramDatabaseFile="bin/HTTPLoadTestd.pdb"
|
||||
SubSystem="1"
|
||||
TargetMachine="1"/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"/>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"/>
|
||||
<Tool
|
||||
Name="VCResourceCompilerTool"/>
|
||||
<Tool
|
||||
Name="VCWebServiceProxyGeneratorTool"/>
|
||||
<Tool
|
||||
Name="VCXMLDataGeneratorTool"/>
|
||||
<Tool
|
||||
Name="VCWebDeploymentTool"/>
|
||||
<Tool
|
||||
Name="VCManagedWrapperGeneratorTool"/>
|
||||
<Tool
|
||||
Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
|
||||
</Configuration>
|
||||
<Configuration
|
||||
Name="release_shared|Win32"
|
||||
OutputDirectory="obj\release_shared"
|
||||
IntermediateDirectory="obj\release_shared"
|
||||
ConfigurationType="1"
|
||||
UseOfMFC="2"
|
||||
CharacterSet="2">
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="4"
|
||||
InlineFunctionExpansion="1"
|
||||
EnableIntrinsicFunctions="TRUE"
|
||||
FavorSizeOrSpeed="1"
|
||||
OmitFramePointers="TRUE"
|
||||
OptimizeForWindowsApplication="TRUE"
|
||||
AdditionalIncludeDirectories=".\include;..\..\..\Foundation\include;..\..\..\XML\include;..\..\..\Net\include;..\..\..\Util\include"
|
||||
PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;POCO_DLL;WINVER=0x0500"
|
||||
StringPooling="TRUE"
|
||||
RuntimeLibrary="2"
|
||||
BufferSecurityCheck="FALSE"
|
||||
TreatWChar_tAsBuiltInType="TRUE"
|
||||
ForceConformanceInForLoopScope="TRUE"
|
||||
RuntimeTypeInfo="TRUE"
|
||||
UsePrecompiledHeader="0"
|
||||
WarningLevel="3"
|
||||
Detect64BitPortabilityProblems="TRUE"
|
||||
DebugInformationFormat="3"/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
AdditionalDependencies="PocoFoundation.lib PocoXML.lib PocoNet.lib PocoUtil.lib"
|
||||
OutputFile="bin/HTTPLoadTest.exe"
|
||||
LinkIncremental="1"
|
||||
AdditionalLibraryDirectories="..\..\..\lib"
|
||||
GenerateDebugInformation="FALSE"
|
||||
ProgramDatabaseFile=""
|
||||
SubSystem="1"
|
||||
OptimizeReferences="2"
|
||||
EnableCOMDATFolding="2"
|
||||
TargetMachine="1"/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"/>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"/>
|
||||
<Tool
|
||||
Name="VCResourceCompilerTool"/>
|
||||
<Tool
|
||||
Name="VCWebServiceProxyGeneratorTool"/>
|
||||
<Tool
|
||||
Name="VCXMLDataGeneratorTool"/>
|
||||
<Tool
|
||||
Name="VCWebDeploymentTool"/>
|
||||
<Tool
|
||||
Name="VCManagedWrapperGeneratorTool"/>
|
||||
<Tool
|
||||
Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
|
||||
</Configuration>
|
||||
</Configurations>
|
||||
<References>
|
||||
</References>
|
||||
<Files>
|
||||
<Filter
|
||||
Name="Source Files"
|
||||
Filter="">
|
||||
<File
|
||||
RelativePath=".\src\HTTPLoadTest.cpp">
|
||||
</File>
|
||||
</Filter>
|
||||
</Files>
|
||||
<Globals>
|
||||
</Globals>
|
||||
</VisualStudioProject>
|
209
Net/samples/HTTPLoadTest/HTTPLoadTest_vs80.vcproj
Normal file
209
Net/samples/HTTPLoadTest/HTTPLoadTest_vs80.vcproj
Normal file
@@ -0,0 +1,209 @@
|
||||
<?xml version="1.0" encoding="Windows-1252"?>
|
||||
<VisualStudioProject
|
||||
ProjectType="Visual C++"
|
||||
Version="8.00"
|
||||
Name="HTTPLoadTest"
|
||||
ProjectGUID="{DC23240B-5266-4486-A141-B8D6F25F7676}"
|
||||
Keyword="Win32Proj"
|
||||
>
|
||||
<Platforms>
|
||||
<Platform
|
||||
Name="Win32"
|
||||
/>
|
||||
</Platforms>
|
||||
<ToolFiles>
|
||||
</ToolFiles>
|
||||
<Configurations>
|
||||
<Configuration
|
||||
Name="debug_shared|Win32"
|
||||
OutputDirectory="obj\debug_shared"
|
||||
IntermediateDirectory="obj\debug_shared"
|
||||
ConfigurationType="1"
|
||||
InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops"
|
||||
UseOfMFC="2"
|
||||
CharacterSet="2"
|
||||
>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXMLDataGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebServiceProxyGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="0"
|
||||
AdditionalIncludeDirectories=".\include;..\..\..\Foundation\include;..\..\..\XML\include;..\..\..\Net\include;..\..\..\Util\include"
|
||||
PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;POCO_DLL;WINVER=0x0500"
|
||||
MinimalRebuild="true"
|
||||
BasicRuntimeChecks="3"
|
||||
RuntimeLibrary="3"
|
||||
BufferSecurityCheck="true"
|
||||
TreatWChar_tAsBuiltInType="true"
|
||||
ForceConformanceInForLoopScope="true"
|
||||
RuntimeTypeInfo="true"
|
||||
UsePrecompiledHeader="0"
|
||||
WarningLevel="3"
|
||||
Detect64BitPortabilityProblems="true"
|
||||
DebugInformationFormat="4"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManagedResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
AdditionalDependencies="PocoFoundationd.lib PocoXMLd.lib PocoNetd.lib PocoUtild.lib"
|
||||
OutputFile="bin/HTTPLoadTestd.exe"
|
||||
LinkIncremental="2"
|
||||
AdditionalLibraryDirectories="..\..\..\lib"
|
||||
GenerateDebugInformation="true"
|
||||
ProgramDatabaseFile="bin/HTTPLoadTestd.pdb"
|
||||
SubSystem="1"
|
||||
TargetMachine="1"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCALinkTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManifestTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXDCMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCBscMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCFxCopTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCAppVerifierTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebDeploymentTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"
|
||||
/>
|
||||
</Configuration>
|
||||
<Configuration
|
||||
Name="release_shared|Win32"
|
||||
OutputDirectory="obj\release_shared"
|
||||
IntermediateDirectory="obj\release_shared"
|
||||
ConfigurationType="1"
|
||||
InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops"
|
||||
UseOfMFC="2"
|
||||
CharacterSet="2"
|
||||
>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXMLDataGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebServiceProxyGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="4"
|
||||
InlineFunctionExpansion="1"
|
||||
EnableIntrinsicFunctions="true"
|
||||
FavorSizeOrSpeed="1"
|
||||
OmitFramePointers="true"
|
||||
AdditionalIncludeDirectories=".\include;..\..\..\Foundation\include;..\..\..\XML\include;..\..\..\Net\include;..\..\..\Util\include"
|
||||
PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;POCO_DLL;WINVER=0x0500"
|
||||
StringPooling="true"
|
||||
RuntimeLibrary="2"
|
||||
BufferSecurityCheck="false"
|
||||
TreatWChar_tAsBuiltInType="true"
|
||||
ForceConformanceInForLoopScope="true"
|
||||
RuntimeTypeInfo="true"
|
||||
UsePrecompiledHeader="0"
|
||||
WarningLevel="3"
|
||||
Detect64BitPortabilityProblems="true"
|
||||
DebugInformationFormat="3"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManagedResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
AdditionalDependencies="PocoFoundation.lib PocoXML.lib PocoNet.lib PocoUtil.lib"
|
||||
OutputFile="bin/HTTPLoadTest.exe"
|
||||
LinkIncremental="1"
|
||||
AdditionalLibraryDirectories="..\..\..\lib"
|
||||
GenerateDebugInformation="false"
|
||||
ProgramDatabaseFile=""
|
||||
SubSystem="1"
|
||||
OptimizeReferences="2"
|
||||
EnableCOMDATFolding="2"
|
||||
TargetMachine="1"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCALinkTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManifestTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXDCMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCBscMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCFxCopTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCAppVerifierTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebDeploymentTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"
|
||||
/>
|
||||
</Configuration>
|
||||
</Configurations>
|
||||
<References>
|
||||
</References>
|
||||
<Files>
|
||||
<Filter
|
||||
Name="Source Files"
|
||||
>
|
||||
<File
|
||||
RelativePath=".\src\HTTPLoadTest.cpp"
|
||||
>
|
||||
</File>
|
||||
</Filter>
|
||||
</Files>
|
||||
<Globals>
|
||||
</Globals>
|
||||
</VisualStudioProject>
|
17
Net/samples/HTTPLoadTest/Makefile
Normal file
17
Net/samples/HTTPLoadTest/Makefile
Normal file
@@ -0,0 +1,17 @@
|
||||
#
|
||||
# Makefile
|
||||
#
|
||||
# $Id: //poco/1.2/Net/samples/HTTPLoadTest/Makefile#1 $
|
||||
#
|
||||
# Makefile for Poco HTTPLoadTest
|
||||
#
|
||||
|
||||
include $(POCO_BASE)/build/rules/global
|
||||
|
||||
objects = HTTPLoadTest
|
||||
|
||||
target = HTTPLoadTest
|
||||
target_version = 1
|
||||
target_libs = PocoUtil PocoNet PocoXML PocoFoundation
|
||||
|
||||
include $(POCO_BASE)/build/rules/exec
|
388
Net/samples/HTTPLoadTest/src/HTTPLoadTest.cpp
Normal file
388
Net/samples/HTTPLoadTest/src/HTTPLoadTest.cpp
Normal file
@@ -0,0 +1,388 @@
|
||||
//
|
||||
// HTTPLoadTest.cpp
|
||||
//
|
||||
// $Id: //poco/1.2/Net/samples/HTTPLoadTest/src/HTTPLoadTest.cpp#1 $
|
||||
//
|
||||
// This sample demonstrates the HTTPClientSession class.
|
||||
//
|
||||
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "Poco/Net/HTTPClientSession.h"
|
||||
#include "Poco/Net/HTTPRequest.h"
|
||||
#include "Poco/Net/HTTPResponse.h"
|
||||
#include "Poco/Net/HTTPCookie.h"
|
||||
#include "Poco/Net/NameValueCollection.h"
|
||||
#include "Poco/Path.h"
|
||||
#include "Poco/URI.h"
|
||||
#include "Poco/AutoPtr.h"
|
||||
#include "Poco/Thread.h"
|
||||
#include "Poco/Mutex.h"
|
||||
#include "Poco/Runnable.h"
|
||||
#include "Poco/Stopwatch.h"
|
||||
#include "Poco/NumberParser.h"
|
||||
#include "Poco/Exception.h"
|
||||
#include "Poco/Util/Application.h"
|
||||
#include "Poco/Util/Option.h"
|
||||
#include "Poco/Util/OptionSet.h"
|
||||
#include "Poco/Util/HelpFormatter.h"
|
||||
#include "Poco/Util/AbstractConfiguration.h"
|
||||
#include <iostream>
|
||||
|
||||
|
||||
using Poco::Net::HTTPClientSession;
|
||||
using Poco::Net::HTTPRequest;
|
||||
using Poco::Net::HTTPResponse;
|
||||
using Poco::Net::HTTPMessage;
|
||||
using Poco::Net::HTTPCookie;
|
||||
using Poco::Net::NameValueCollection;
|
||||
using Poco::Util::Application;
|
||||
using Poco::Util::Option;
|
||||
using Poco::Util::OptionSet;
|
||||
using Poco::Util::HelpFormatter;
|
||||
using Poco::Util::AbstractConfiguration;
|
||||
using Poco::AutoPtr;
|
||||
using Poco::Thread;
|
||||
using Poco::FastMutex;
|
||||
using Poco::Runnable;
|
||||
using Poco::Stopwatch;
|
||||
using Poco::NumberParser;
|
||||
using Poco::Path;
|
||||
using Poco::URI;
|
||||
using Poco::Exception;
|
||||
|
||||
class HTTPClient : public Runnable
|
||||
{
|
||||
public:
|
||||
HTTPClient(const URI& uri, int repetitions, bool cookies=false, bool verbose=false):
|
||||
_uri(uri),
|
||||
_cookies(cookies),
|
||||
_verbose(verbose),
|
||||
_repetitions(repetitions),
|
||||
_usec(0),
|
||||
_success(0)
|
||||
{
|
||||
_gRepetitions += _repetitions;
|
||||
}
|
||||
|
||||
~HTTPClient()
|
||||
{
|
||||
}
|
||||
|
||||
void run()
|
||||
{
|
||||
Stopwatch sw;
|
||||
std::vector<HTTPCookie> cookies;
|
||||
|
||||
for (int i = 0; i < _repetitions; ++i)
|
||||
{
|
||||
try
|
||||
{
|
||||
int usec = 0;
|
||||
std::string path(_uri.getPathAndQuery());
|
||||
if (path.empty()) path = "/";
|
||||
|
||||
HTTPClientSession session(_uri.getHost(), _uri.getPort());
|
||||
HTTPRequest req(HTTPRequest::HTTP_GET, path, HTTPMessage::HTTP_1_1);
|
||||
|
||||
if (_cookies)
|
||||
{
|
||||
NameValueCollection nvc;
|
||||
std::vector<HTTPCookie>::iterator it = cookies.begin();
|
||||
for(; it != cookies.end(); ++it)
|
||||
nvc.add((*it).getName(), (*it).getValue());
|
||||
|
||||
req.setCookies(nvc);
|
||||
}
|
||||
|
||||
HTTPResponse res;
|
||||
sw.restart();
|
||||
session.sendRequest(req);
|
||||
std::istream& rs = session.receiveResponse(res);
|
||||
sw.stop();
|
||||
_success += HTTPResponse::HTTP_OK == res.getStatus() ? 1 : 0;
|
||||
if (_cookies) res.getCookies(cookies);
|
||||
usec = sw.elapsed();
|
||||
|
||||
if (_verbose)
|
||||
{
|
||||
FastMutex::ScopedLock lock(_mutex);
|
||||
std::cout
|
||||
<< _uri.toString() << ' ' << res.getStatus() << ' ' << res.getReason()
|
||||
<< ' ' << usec/1000.0 << "ms" << std::endl;
|
||||
}
|
||||
|
||||
_usec += usec;
|
||||
}
|
||||
catch (Exception& exc)
|
||||
{
|
||||
FastMutex::ScopedLock lock(_mutex);
|
||||
std::cerr << exc.displayText() << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
FastMutex::ScopedLock lock(_mutex);
|
||||
_gSuccess += _success;
|
||||
_gUsec += _usec;
|
||||
}
|
||||
if (_verbose)
|
||||
printStats(_uri.toString(), _repetitions, _success, _usec);
|
||||
}
|
||||
|
||||
static void printStats(std::string uri, int repetitions, int success, Poco::UInt64 usec);
|
||||
static int totalAttempts();
|
||||
static Poco::UInt64 totalMicroseconds();
|
||||
static int totalSuccessCount();
|
||||
|
||||
private:
|
||||
HTTPClient();
|
||||
|
||||
URI _uri;
|
||||
bool _verbose;
|
||||
bool _cookies;
|
||||
int _repetitions;
|
||||
Poco::UInt64 _usec;
|
||||
int _success;
|
||||
static int _gRepetitions;
|
||||
static Poco::UInt64 _gUsec;
|
||||
static int _gSuccess;
|
||||
static FastMutex _mutex;
|
||||
};
|
||||
|
||||
FastMutex HTTPClient::_mutex;
|
||||
int HTTPClient::_gRepetitions;
|
||||
Poco::UInt64 HTTPClient::_gUsec;
|
||||
int HTTPClient::_gSuccess;
|
||||
|
||||
int HTTPClient::totalAttempts()
|
||||
{
|
||||
return _gRepetitions;
|
||||
}
|
||||
|
||||
Poco::UInt64 HTTPClient::totalMicroseconds()
|
||||
{
|
||||
return _gUsec;
|
||||
}
|
||||
|
||||
int HTTPClient::totalSuccessCount()
|
||||
{
|
||||
return _gSuccess;
|
||||
}
|
||||
|
||||
void HTTPClient::printStats(std::string uri, int repetitions, int success, Poco::UInt64 usec)
|
||||
{
|
||||
FastMutex::ScopedLock lock(_mutex);
|
||||
|
||||
std::cout << std::endl << "--------------" << std::endl
|
||||
<< "Statistics for " << uri << std::endl << "--------------"
|
||||
<< std::endl
|
||||
<< repetitions << " attempts, " << success << " succesful ("
|
||||
<< ((float) success / (float) repetitions) * 100.0 << "%)" << std::endl
|
||||
<< "Avg response time: " << ((float) usec / (float) repetitions) / 1000.0 << "ms, " << std::endl
|
||||
<< "Avg requests/second handled: " << ((float) success /((float) usec / 1000000.0)) << std::endl
|
||||
<< "Total time: " << (float) usec / 1000000.0 << std::endl;
|
||||
}
|
||||
|
||||
class HTTPLoadTest: public Application
|
||||
/// This sample demonstrates some of the features of the Poco::Util::Application class,
|
||||
/// such as configuration file handling and command line arguments processing.
|
||||
///
|
||||
/// Try HTTPLoadTest --help (on Unix platforms) or HTTPLoadTest /help (elsewhere) for
|
||||
/// more information.
|
||||
{
|
||||
public:
|
||||
HTTPLoadTest():
|
||||
_helpRequested(false),
|
||||
_repetitions(1),
|
||||
_threads(1),
|
||||
_verbose(false),
|
||||
_cookies(false)
|
||||
{
|
||||
}
|
||||
|
||||
protected:
|
||||
void initialize(Application& self)
|
||||
{
|
||||
loadConfiguration(); // load default configuration files, if present
|
||||
Application::initialize(self);
|
||||
// add your own initialization code here
|
||||
}
|
||||
|
||||
void uninitialize()
|
||||
{
|
||||
// add your own uninitialization code here
|
||||
Application::uninitialize();
|
||||
}
|
||||
|
||||
void reinitialize(Application& self)
|
||||
{
|
||||
Application::reinitialize(self);
|
||||
// add your own reinitialization code here
|
||||
}
|
||||
|
||||
void defineOptions(OptionSet& options)
|
||||
{
|
||||
Application::defineOptions(options);
|
||||
|
||||
options.addOption(
|
||||
Option("help", "h", "display help information on command line arguments")
|
||||
.required(false)
|
||||
.repeatable(false));
|
||||
|
||||
options.addOption(
|
||||
Option("verbose", "v", "display messages on stdout")
|
||||
.required(false)
|
||||
.repeatable(false));
|
||||
|
||||
options.addOption(
|
||||
Option("cookies", "c", "resend cookies")
|
||||
.required(false)
|
||||
.repeatable(false));
|
||||
|
||||
options.addOption(
|
||||
Option("uri", "u", "HTTP URI")
|
||||
.required(true)
|
||||
.repeatable(false)
|
||||
.argument("uri"));
|
||||
|
||||
options.addOption(
|
||||
Option("repetitions", "r", "fetch repetitions")
|
||||
.required(false)
|
||||
.repeatable(false)
|
||||
.argument("repetitions"));
|
||||
|
||||
options.addOption(
|
||||
Option("threads", "t", "thread count")
|
||||
.required(false)
|
||||
.repeatable(false)
|
||||
.argument("threads"));
|
||||
}
|
||||
|
||||
void handleOption(const std::string& name, const std::string& value)
|
||||
{
|
||||
Application::handleOption(name, value);
|
||||
|
||||
if (name == "help")
|
||||
_helpRequested = true;
|
||||
else if (name == "verbose")
|
||||
_verbose = true;
|
||||
else if (name == "cookies")
|
||||
_cookies = true;
|
||||
else if (name == "uri")
|
||||
_uri = value;
|
||||
else if (name == "repetitions")
|
||||
_repetitions = NumberParser::parse(value);
|
||||
else if (name == "threads")
|
||||
_threads = NumberParser::parse(value);
|
||||
}
|
||||
|
||||
void displayHelp()
|
||||
{
|
||||
HelpFormatter helpFormatter(options());
|
||||
helpFormatter.setCommand(commandName());
|
||||
helpFormatter.setUsage("OPTIONS");
|
||||
helpFormatter.setHeader("A sample application that demonstrates some of the features of the Poco::Util::Application class.");
|
||||
helpFormatter.format(std::cout);
|
||||
}
|
||||
|
||||
void defineProperty(const std::string& def)
|
||||
{
|
||||
std::string name;
|
||||
std::string value;
|
||||
std::string::size_type pos = def.find('=');
|
||||
if (pos != std::string::npos)
|
||||
{
|
||||
name.assign(def, 0, pos);
|
||||
value.assign(def, pos + 1, def.length() - pos);
|
||||
}
|
||||
else name = def;
|
||||
config().setString(name, value);
|
||||
}
|
||||
|
||||
int main(const std::vector<std::string>& args)
|
||||
{
|
||||
if (_helpRequested)
|
||||
{
|
||||
displayHelp();
|
||||
}
|
||||
else
|
||||
{
|
||||
URI uri(_uri);
|
||||
std::vector<Thread*> threads;
|
||||
|
||||
Stopwatch sw;
|
||||
sw.start();
|
||||
for (int i = 0; i < _threads; ++i)
|
||||
{
|
||||
Thread* pt = new Thread(_uri);
|
||||
poco_check_ptr(pt);
|
||||
threads.push_back(pt);
|
||||
HTTPClient* pHTTPClient = new HTTPClient(uri, _repetitions, _cookies, _verbose);
|
||||
poco_check_ptr(pHTTPClient);
|
||||
threads.back()->start(*pHTTPClient);
|
||||
}
|
||||
|
||||
std::vector<Thread*>::iterator it = threads.begin();
|
||||
for(; it != threads.end(); ++it)
|
||||
{
|
||||
(*it)->join();
|
||||
delete *it;
|
||||
}
|
||||
sw.stop();
|
||||
|
||||
HTTPClient::printStats(_uri, HTTPClient::totalAttempts(), HTTPClient::totalSuccessCount(), sw.elapsed());
|
||||
}
|
||||
|
||||
return Application::EXIT_OK;
|
||||
}
|
||||
|
||||
private:
|
||||
bool _helpRequested;
|
||||
bool _verbose;
|
||||
bool _cookies;
|
||||
std::string _uri;
|
||||
int _repetitions;
|
||||
int _threads;
|
||||
};
|
||||
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
AutoPtr<HTTPLoadTest> pApp = new HTTPLoadTest;
|
||||
try
|
||||
{
|
||||
pApp->init(argc, argv);
|
||||
}
|
||||
catch (Poco::Exception& exc)
|
||||
{
|
||||
pApp->logger().log(exc);
|
||||
return Application::EXIT_CONFIG;
|
||||
}
|
||||
return pApp->run();
|
||||
}
|
||||
|
Reference in New Issue
Block a user