Update of /cvsroot/objecthandler/log4cxx-0.9.7/performance
In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv25784/performance
Added Files:
Makefile.am logging.sh main.cpp nullappender.cpp
nullappender.h
Log Message:
--- NEW FILE: logging.sh ---
# Test the performance of logging
# Set the variable REMOTE_HOST to the appropriate value for the
# to perform SocketAppender measurements.
LCF=logging.lcf
TARGET_FILE=test
DELAY=1000
PORT=12345
# The results are somehow RUN_LENGTH dependent. Keep RUN_LENGTH the
# same to be able to compare results
LONGRUN=100000
SHORTRUN=5000
#LONGRUN=1
#SHORTRUN=2
declare -i start=$1
#D=-Dlog4j.configDebug
# -------------------------------------------------------------
function multiRun() {
lcf=$1
loopLength=$2
msg=$3
runLength=$4
echo -n "Results: "
declare -i total
declare -i i
i=0
total=0
while [ $i -lt $loopLength ]
do
i=$i+1
x=$(./logging $lcf $runLength $5)
if [ $x -lt 100 ]; then
echo -n " "
fi
echo -n "$x "
total=$total+$x
done
while [ $i -lt 8 ]
do
i=$i+1
echo -n " "
done
average=$[ $total / $loopLength ]
echo "- average $average $msg"
}
# =============================================
# Echo to $LCF
# =============================================
function lecho {
echo $* >> $LCF
}
# =============================================
echo "--------------" $(date) "---------------"
echo echo "Starting performance measures. This make take a few minutes...."
declare -i TEST
echo; echo "NullAppender:"; echo
TEST=1
if [ $TEST -ge $start ]; then
multiRun xml/logging$TEST.xml 4 "SimpleLayout" $LONGRUN
fi
TEST=2
if [ $TEST -ge $start ]; then
format="%p - %m%n"
multiRun xml/logging$TEST.xml 4 "PatternLayout \"$format\"" $LONGRUN
fi
TEST=3
if [ $TEST -ge $start ]; then
format="%-5p - %m%n"
multiRun xml/logging$TEST.xml 4 "PatternLayout \"$format\"" $LONGRUN
fi
TEST=4
if [ $TEST -ge $start ]; then
multiRun xml/logging$TEST.xml 4 "TTCCLayout/RELATIVE" $LONGRUN
fi
TEST=5
if [ $TEST -ge $start ]; then
format="%r [%t] %-5p %c{2} %x - %m%n"
multiRun xml/logging$TEST.xml 4 "PatternLayout \"$format\"" $LONGRUN
fi
TEST=6
if [ $TEST -ge $start ]; then
format="%r [%t] %-5p %.10c %x - %m%n"
multiRun xml/logging$TEST.xml 4 "PatternLayout \"$format\"" $LONGRUN
fi
TEST=7
if [ $TEST -ge $start ]; then
format="%r [%t] %-5p %.20c %x - %m%n"
multiRun xml/logging$TEST.xml 4 "PatternLayout \"$format\"" $LONGRUN
fi
TEST=8
if [ $TEST -ge $start ]; then
format="%r [%t] %-5p %c - %m%n"
multiRun xml/logging$TEST.xml 4 "PatternLayout \"$format\"" $LONGRUN
fi
TEST=9
if [ $TEST -ge $start ]; then
multiRun xml/logging$TEST.xml 4 "TTCCLayout/ISO8601" $LONGRUN
fi
TEST=10
if [ $TEST -ge $start ]; then
format="%d{ISO8601} [%t] %-5p %c %x - %m%n"
multiRun xml/logging$TEST.xml 4 "PatternLayout \"$format\"" $LONGRUN
fi
TEST=11
if [ $TEST -ge $start ]; then
format="%d{yyyy-MM-dd HH:mm:ss,SSS} [%t] %-5p %c %x - %m%n"
multiRun xml/logging$TEST.xml 4 "PatternLayout \"$format\"" $LONGRUN
fi
TEST=12
if [ $TEST -ge $start ]; then
format="%l - %m%n"
multiRun xml/logging$TEST.xml 4 "PatternLayout \"$format\"" $SHORTRUN
fi
TEST=13
if [ $TEST -ge $start ]; then
format="%F.%L - %m%n"
multiRun xml/logging$TEST.xml 4 "PatternLayout \"$format\"" $SHORTRUN
fi
echo
echo "FileAppender: "
echo
TEST=100
if [ $TEST -ge $start ]; then
multiRun xml/logging$TEST.xml 8 "SimpleLayout" $LONGRUN
fi
TEST=101
if [ $TEST -ge $start ]; then
format="%p - %m%n"
multiRun xml/logging$TEST.xml 8 "PatternLayout \"$format\"" $LONGRUN
fi
TEST=102
if [ $TEST -ge $start ]; then
multiRun xml/logging$TEST.xml 8 "TTCC/RELATIVE" $LONGRUN
fi
TEST=103
if [ $TEST -ge $start ]; then
format="%r [%t] %-5p %c - %m%n"
multiRun xml/logging$TEST.xml 8 "PatternLayout \"$format\"" $LONGRUN
fi
TEST=104
if [ $TEST -ge $start ]; then
multiRun xml/logging$TEST.xml 8 "TTCCLayout/ISO8601" $LONGRUN
fi
TEST=105
if [ $TEST -ge $start ]; then
format="%d{ISO8601} [%t] %-5p %c %x - %m%n"
multiRun xml/logging$TEST.xml 8 "PatternLayout \"$format\"" $LONGRUN
fi
TEST=106
if [ $TEST -ge $start ]; then
format="%d{yyyy-MM-dd HH:mm:ss,SSS} [%t] %-5p %c %x - %m%n"
multiRun xml/logging$TEST.xml 8 "PatternLayout \"$format\"" $LONGRUN
fi
echo ================== 107 ===============================
TEST=107
if [ $TEST -ge $start ]; then
format="%l - %m%n"
multiRun xml/logging$TEST.xml 8 "PatternLayout \"$format\"" $SHORTRUN
fi
echo -------------------------------------
echo "FileAppender: ImmediateFlush=false"
echo -------------------------------------
TEST=200
if [ $TEST -ge $start ]; then
multiRun xml/logging$TEST.xml 8 "SimpleLayout" $LONGRUN
fi
TEST=201
if [ $TEST -ge $start ]; then
format="%p - %m%n"
multiRun xml/logging$TEST.xml 8 "PatternLayout \"$format\"" $LONGRUN
fi
TEST=202
if [ $TEST -ge $start ]; then
multiRun xml/logging$TEST.xml 8 "TTCC/RELATIVE" $LONGRUN
fi
TEST=203
if [ $TEST -ge $start ]; then
format="%r [%t] %-5p %c - %m%n"
multiRun xml/logging$TEST.xml 8 "PatternLayout \"$format\"" $LONGRUN
fi
TEST=204
if [ $TEST -ge $start ]; then
multiRun xml/logging$TEST.xml 8 "TTCCLayout/ISO8601" $LONGRUN
fi
TEST=205
if [ $TEST -ge $start ]; then
format="%d{ISO8601} [%t] %-5p %c %x - %m%n"
multiRun xml/logging$TEST.xml 8 "PatternLayout \"$format\"" $LONGRUN
fi
TEST=206
if [ $TEST -ge $start ]; then
format="%d{yyyy-MM-dd HH:mm:ss,SSS} [%t] %-5p %c %x - %m%n"
multiRun xml/logging$TEST.xml 8 "PatternLayout \"$format\"" $LONGRUN
fi
TEST=207
if [ $TEST -ge $start ]; then
format="%l - %m%n"
multiRun xml/logging$TEST.xml 8 "PatternLayout \"$format\"" $SHORTRUN
fi
echo -------------------------------------
echo "FileAppender: BufferedIO=true"
echo -------------------------------------
TEST=220
if [ $TEST -ge $start ]; then
multiRun xml/logging$TEST.xml 8 "SimpleLayout" $LONGRUN
fi
TEST=221
if [ $TEST -ge $start ]; then
format="%p - %m%n"
multiRun xml/logging$TEST.xml 8 "PatternLayout \"$format\"" $LONGRUN
fi
TEST=222
if [ $TEST -ge $start ]; then
multiRun xml/logging$TEST.xml 8 "TTCC/RELATIVE" $LONGRUN
fi
TEST=223
if [ $TEST -ge $start ]; then
format="%r [%t] %-5p %c - %m%n"
multiRun xml/logging$TEST.xml 8 "PatternLayout \"$format\"" $LONGRUN
fi
TEST=224
if [ $TEST -ge $start ]; then
multiRun xml/logging$TEST.xml 8 "TTCCLayout/ISO8601" $LONGRUN
fi
TEST=225
if [ $TEST -ge $start ]; then
format="%d{ISO8601} [%t] %-5p %c %x - %m%n"
multiRun xml/logging$TEST.xml 8 "PatternLayout \"$format\"" $LONGRUN
fi
TEST=226
if [ $TEST -ge $start ]; then
format="%d{yyyy-MM-dd HH:mm:ss,SSS} [%t] %-5p %c %x - %m%n"
multiRun xml/logging$TEST.xml 8 "PatternLayout \"$format\"" $LONGRUN
fi
TEST=227
if [ $TEST -ge $start ]; then
format="%l - %m%n"
multiRun xml/logging$TEST.xml 8 "PatternLayout \"$format\"" $SHORTRUN
fi
echo ==================================
echo Async appender
echo ==================================
TEST=300
if [ $TEST -ge $start ]; then
multiRun xml/logging$TEST.xml 8 "SimpleLayout" $LONGRUN
fi
TEST=301
if [ $TEST -ge $start ]; then
format="%p - %m%n"
multiRun xml/logging$TEST.xml 8 "PatternLayout \"$format\"" $LONGRUN
fi
TEST=302
if [ $TEST -ge $start ]; then
multiRun xml/logging$TEST.xml 8 "TTCCLayout/RELATIVE" $LONGRUN
fi
TEST=303
if [ $TEST -ge $start ]; then
format="%r [%t] %-5p %c - %m%n"
multiRun xml/logging$TEST.xml 8 "PatternLayout \"$format\"" $LONGRUN
fi
TEST=304
if [ $TEST -ge $start ]; then
multiRun xml/logging$TEST.xml 8 "TTCCLayout/ISO8601" $LONGRUN
fi
TEST=305
if [ $TEST -ge $start ]; then
format="%d{ISO8601} [%t] %-5p %c %x - %m%n"
multiRun xml/logging$TEST.xml 8 "PatternLayout \"$format\"" $LONGRUN
fi
TEST=306
if [ $TEST -ge $start ]; then
format="%d{yyyy-MM-dd HH:mm:ss,SSS} [%t] %-5p %c %x - %m%n"
multiRun xml/logging$TEST.xml 8 "PatternLayout \"$format\"" $LONGRUN
fi
TEST=307
if [ $TEST -ge $start ]; then
format="%l - %m%n"
multiRun xml/logging$TEST.xml 8 "PatternLayout \"$format\"" $SHORTRUN
fi
# ===============================================================
# Remote logging
# ===============================================================
TEST=1000
#RL=1000
RL=10000
if [ $TEST -ge $start ]; then
./logging xml/logging$TEST.xml $RL 100 100
#multiRun 4 "SocketAppender" $SHORTRUN $DELAY
fi
TEST=1001
#RL=1000
RL=30000
if [ $TEST -ge $start ]; then
./logging xml/logging$TEST.xml $RL
#multiRun 4 "SocketAppender" $SHORTRUN $DELAY
fi
--- NEW FILE: nullappender.h ---
/*
* Copyright 2003,2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef _LOG4CXX_PERFORMANCE_NULL_APPENDER_H
#define _LOG4CXX_PERFORMANCE_NULL_APPENDER_H
#include <log4cxx/config.h>
#include <log4cxx/helpers/tchar.h>
#include <log4cxx/appenderskeleton.h>
namespace log4cxx
{
class Layout;
typedef helpers::ObjectPtrT<Layout> LayoutPtr;
namespace performance
{
class NullAppender;
typedef helpers::ObjectPtrT<NullAppender> NullAppenderPtr;
/**
* A bogus appender which calls the format method of its layout object
* but does not write the result anywhere.
* */
class NullAppender : public AppenderSkeleton
{
public:
StringBuffer sbuf;
DECLARE_LOG4CXX_OBJECT(NullAppender)
BEGIN_LOG4CXX_CAST_MAP()
LOG4CXX_CAST_ENTRY(NullAppender)
LOG4CXX_CAST_ENTRY_CHAIN(AppenderSkeleton)
END_LOG4CXX_CAST_MAP()
NullAppender();
NullAppender(const LayoutPtr& layout);
void close();
void doAppend(const spi::LoggingEventPtr& event);
void append(const spi::LoggingEventPtr& event);
/**
This is a bogus appender but it still uses a layout.
*/
bool requiresLayout() const;
}; // NullAppender
} // namespace performance
}; // namespace log4cxx
#endif //_LOG4CXX_PERFORMANCE_NULL_APPENDER_H
--- NEW FILE: Makefile.am ---
SUBDIRS = xml
noinst_PROGRAMS = logging
performanceincdir = $(includedir)/log4cxx
noinst_HEADERS= $(top_srcdir)/performance/*.h
INCLUDES = -I$(top_srcdir)/include
logging_SOURCES = main.cpp nullappender.cpp
logging_LDADD = $(top_builddir)/src/liblog4cxx.la
EXTRA_DIST = logging.sh
--- NEW FILE: main.cpp ---
/*
* Copyright 2003,2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <log4cxx/helpers/tchar.h>
#include <log4cxx/ndc.h>
#include <log4cxx/logmanager.h>
#include <log4cxx/logger.h>
#include <log4cxx/helpers/exception.h>
#include <log4cxx/helpers/optionconverter.h>
#include <log4cxx/xml/domconfigurator.h>
#include <log4cxx/helpers/system.h>
#include <log4cxx/helpers/thread.h>
using namespace log4cxx;
using namespace log4cxx::helpers;
int runLength;
int delay = -1;
/*
A delay is applied after every <code>burstLen</code> log
requests. The default value of this constant is 100. */
int burstLen = 100;
int DELAY_MULT = 1000/burstLen;
LoggerPtr logger = Logger::getLogger(_T("A0123456789.B0123456789.C0123456789"));
void Usage(const String& processName, const String& msg)
{
tcerr << msg << std::endl;
tcerr <<
_T("Usage: ") << processName
<< _T(" confFile runLength [delay] [burstLen]") << std::endl
<< _T(" confFile is an XML configuration file and") << std::endl
<< _T(" runLength (integer) is the length of test loop.") << std::endl
<< _T(" delay is the time in millisecs to wait every burstLen log requests.") << std::endl;
exit(EXIT_FAILURE);
}
void init(const String& configFile, const String& runLengthStr,
const String& delayStr, const String& burstLenStr)
{
runLength = OptionConverter::toInt(runLengthStr, runLength);
if (runLength < 1)
{
throw IllegalArgumentException(_T("run Length must be greater than 0"));
}
if (!delayStr.empty())
{
delay = OptionConverter::toInt(delayStr, delay);
}
if (!burstLenStr.empty())
{
burstLen = OptionConverter::toInt(burstLenStr, burstLen);
DELAY_MULT = 1000/burstLen;
}
#ifdef HAVE_XML
xml::DOMConfigurator::configure(configFile);
#endif
}
double NoDelayLoop(LoggerPtr logger, const String& msg)
{
int64_t before = System::currentTimeMillis();
for(int i = 0; i < runLength; i++)
{
logger->info(msg, __FILE__, __LINE__);
}
int64_t after = System::currentTimeMillis();
return ((after - before)*1000.0)/runLength;
}
double DelayedLoop(LoggerPtr logger, const String& msg)
{
int64_t before = System::currentTimeMillis();
int j = 0;
for(int i = 0; i < runLength; i++)
{
logger->info(msg);
if(j++ == burstLen)
{
j = 0;
try
{
Thread::sleep(delay);
}
catch(Exception&)
{
}
}
}
double actualTime = ((System::currentTimeMillis()-before)*1000.0/runLength);
tcout << "actual time: " << actualTime << std::endl;
return (actualTime - delay*DELAY_MULT);
}
int main(int argc, char* argv[])
{
int ret = EXIT_SUCCESS;
try
{
USES_CONVERSION;
if(argc == 3)
init(A2T(argv[1]), A2T(argv[2]), String(), String());
else if(argc == 5)
init(A2T(argv[1]), A2T(argv[2]), A2T(argv[3]), A2T(argv[4]));
else
Usage(A2T(argv[0]), _T("Wrong number of arguments."));
NDC::push(_T("some context"));
double delta;
String msg = _T("ABCDEGHIJKLMNOPQRSTUVWXYZabcdeghijklmnopqrstuvwxyz1234567890");
if(delay <= 0)
{
delta = NoDelayLoop(logger, msg);
}
else
{
delta = DelayedLoop(logger, msg);
}
tcout << (int)delta << std::endl;
LogManager::shutdown();
}
catch(Exception&)
{
ret = EXIT_FAILURE;
}
return ret;
}
--- NEW FILE: nullappender.cpp ---
/*
* Copyright 2003,2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "nullappender.h"
using namespace log4cxx;
using namespace log4cxx::helpers;
using namespace log4cxx::spi;
using namespace log4cxx::performance;
IMPLEMENT_LOG4CXX_OBJECT(NullAppender)
NullAppender::NullAppender()
{
}
NullAppender::NullAppender(const LayoutPtr& layout)
{
this->layout = layout;
}
void NullAppender::close()
{
}
void NullAppender::doAppend(const LoggingEventPtr& event)
{
if (layout != 0)
{
sbuf.seekp(0);
layout->format(sbuf, event);
}
}
void NullAppender::append(const LoggingEventPtr& event)
{
}
/**
This is a bogus appender but it still uses a layout.
*/
bool NullAppender::requiresLayout() const
{
return true;
}
|