diff options
author | irfan <irfan@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 1999-06-14 01:18:02 +0000 |
---|---|---|
committer | irfan <irfan@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 1999-06-14 01:18:02 +0000 |
commit | a43d81d54a95a6fd5359d4733b7e3c1e4f02bd6b (patch) | |
tree | 6848bcf6edc3972f86acb468036c0aac7d08b031 /performance-tests | |
parent | d6a1ac51256b1bbe81b983706e82db60832b26ac (diff) | |
download | ATCD-a43d81d54a95a6fd5359d4733b7e3c1e4f02bd6b.tar.gz |
*** empty log message ***
Diffstat (limited to 'performance-tests')
6 files changed, 623 insertions, 7 deletions
diff --git a/performance-tests/Server_Concurrency/Latency_Stats.h b/performance-tests/Server_Concurrency/Latency_Stats.h new file mode 100644 index 00000000000..f64aa1fd67b --- /dev/null +++ b/performance-tests/Server_Concurrency/Latency_Stats.h @@ -0,0 +1,117 @@ +// $Id$ + +class Latency_Stats +{ +public: + Latency_Stats (void); + + void dump_results (const char* test_name, + const char* sub_test); + + void sample (ACE_hrtime_t sample); + + void accumulate (const Latency_Stats& stats); + // Useful to merge several Latency_Stats. + +private: + u_long n_; + ACE_hrtime_t sum_; + ACE_hrtime_t sum2_; + ACE_hrtime_t min_; + ACE_hrtime_t max_; +}; + +inline +Latency_Stats::Latency_Stats (void) + : n_ (0), + sum_ (0), + sum2_ (0), + min_ (0), + max_ (0) +{ +} + +inline void +Latency_Stats::sample (ACE_hrtime_t sample) +{ + this->sum_ += sample; + this->sum2_ += sample * sample; + if (this->n_ == 0) + { + this->min_ = sample; + this->max_ = sample; + } + else if (this->min_ > sample) + this->min_ = sample; + else if (this->max_ < sample) + this->max_ = sample; + this->n_++; +} + +inline void +Latency_Stats::dump_results (const char *test_name, + const char *sub_test) +{ + if (this->n_ <= 1) + return; + + ACE_hrtime_t avg = this->sum_ / this->n_; + ACE_hrtime_t dev = + this->sum2_ / this->n_ - avg*avg; + + ACE_UINT32 gsf = ACE_High_Res_Timer::global_scale_factor (); + + double min_usec = ACE_CU64_TO_CU32 (this->min_) / gsf; + double max_usec = ACE_CU64_TO_CU32 (this->max_) / gsf; + double avg_usec = ACE_CU64_TO_CU32 (avg) / gsf; + double dev_usec = ACE_CU64_TO_CU32 (dev) / (gsf * gsf); + ACE_DEBUG ((LM_DEBUG, + "%s/%s: %.2f/%.2f/%.2f/%.2f (min/avg/max/var^2) [usecs]\n", + test_name, sub_test, + min_usec, avg_usec, max_usec, dev_usec)); +} + +inline void +Latency_Stats::accumulate (const Latency_Stats& rhs) +{ + if (rhs.n_ == 0) + return; + + if (this->n_ == 0) + { + *this = rhs; + return; + } + + if (this->min_ > rhs.min_) + this->min_ = rhs.min_; + if (this->max_ < rhs.max_) + this->max_ = rhs.max_; + + this->sum_ += rhs.sum_; + this->sum2_ += rhs.sum2_; + this->n_ += rhs.n_; +} + +inline void +move_to_rt_class (void) +{ + // Enable FIFO scheduling, e.g., RT scheduling class on Solaris. + int priority = + (ACE_Sched_Params::priority_min (ACE_SCHED_FIFO) + + ACE_Sched_Params::priority_max (ACE_SCHED_FIFO)) / 2; + + int result = ACE_OS::sched_params (ACE_Sched_Params (ACE_SCHED_FIFO, + priority, + ACE_SCOPE_PROCESS)); + if (result == 0) + { + result = ACE_OS::thr_setprio (priority); + } + + if (result != 0) + { + ACE_DEBUG ((LM_DEBUG, + "Cannot move program to realtime class.\n")); + } +} diff --git a/performance-tests/Server_Concurrency/Leader_Follower/Leader_Follower.dsp b/performance-tests/Server_Concurrency/Leader_Follower/Leader_Follower.dsp new file mode 100644 index 00000000000..b1bf8fdafae --- /dev/null +++ b/performance-tests/Server_Concurrency/Leader_Follower/Leader_Follower.dsp @@ -0,0 +1,102 @@ +# Microsoft Developer Studio Project File - Name="Leader_Follower" - Package Owner=<4>
+# Microsoft Developer Studio Generated Build File, Format Version 6.00
+# ** DO NOT EDIT **
+
+# TARGTYPE "Win32 (x86) Console Application" 0x0103
+
+CFG=Leader_Follower - Win32 Debug
+!MESSAGE This is not a valid makefile. To build this project using NMAKE,
+!MESSAGE use the Export Makefile command and run
+!MESSAGE
+!MESSAGE NMAKE /f "Leader_Follower.mak".
+!MESSAGE
+!MESSAGE You can specify a configuration when running NMAKE
+!MESSAGE by defining the macro CFG on the command line. For example:
+!MESSAGE
+!MESSAGE NMAKE /f "Leader_Follower.mak" CFG="Leader_Follower - Win32 Debug"
+!MESSAGE
+!MESSAGE Possible choices for configuration are:
+!MESSAGE
+!MESSAGE "Leader_Follower - Win32 Release" (based on "Win32 (x86) Console Application")
+!MESSAGE "Leader_Follower - Win32 Debug" (based on "Win32 (x86) Console Application")
+!MESSAGE
+
+# Begin Project
+# PROP AllowPerConfigDependencies 0
+# PROP Scc_ProjName ""
+# PROP Scc_LocalPath ""
+CPP=cl.exe
+RSC=rc.exe
+
+!IF "$(CFG)" == "Leader_Follower - Win32 Release"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 0
+# PROP BASE Output_Dir "Release"
+# PROP BASE Intermediate_Dir "Release"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 0
+# PROP Output_Dir "Release"
+# PROP Intermediate_Dir "Release"
+# PROP Ignore_Export_Lib 0
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
+# ADD CPP /nologo /MD /W3 /GX /O2 /I "..\..\.." /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
+# ADD BASE RSC /l 0x409 /d "NDEBUG"
+# ADD RSC /l 0x409 /d "NDEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
+# ADD LINK32 ace.lib /nologo /subsystem:console /machine:I386 /libpath:"..\..\..\ace"
+
+!ELSEIF "$(CFG)" == "Leader_Follower - Win32 Debug"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 1
+# PROP BASE Output_Dir "Debug"
+# PROP BASE Intermediate_Dir "Debug"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 1
+# PROP Output_Dir ""
+# PROP Intermediate_Dir "Debug"
+# PROP Ignore_Export_Lib 0
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /W3 /Gm /GX /Zi /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
+# ADD CPP /nologo /MDd /W3 /Gm /GX /Zi /Od /I "..\..\.." /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
+# ADD BASE RSC /l 0x409 /d "_DEBUG"
+# ADD RSC /l 0x409 /d "_DEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
+# ADD LINK32 aced.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept /libpath:"..\..\..\ace"
+
+!ENDIF
+
+# Begin Target
+
+# Name "Leader_Follower - Win32 Release"
+# Name "Leader_Follower - Win32 Debug"
+# Begin Group "Source Files"
+
+# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
+# Begin Source File
+
+SOURCE=.\leader_follower.cpp
+# End Source File
+# End Group
+# Begin Group "Header Files"
+
+# PROP Default_Filter "h;hpp;hxx;hm;inl"
+# End Group
+# Begin Group "Resource Files"
+
+# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
+# End Group
+# End Target
+# End Project
diff --git a/performance-tests/Server_Concurrency/Leader_Follower/Leader_Follower.dsw b/performance-tests/Server_Concurrency/Leader_Follower/Leader_Follower.dsw new file mode 100644 index 00000000000..7b90119e3f1 --- /dev/null +++ b/performance-tests/Server_Concurrency/Leader_Follower/Leader_Follower.dsw @@ -0,0 +1,28 @@ +Microsoft Developer Studio Workspace File, Format Version 6.00
+# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!
+
+###############################################################################
+
+Project: "Leader_Follower"=".\Leader_Follower.dsp" - Package Owner=<4>
+
+Package=<5>
+{{{
+}}}
+
+Package=<4>
+{{{
+}}}
+
+###############################################################################
+
+Global:
+
+Package=<5>
+{{{
+}}}
+
+Package=<3>
+{{{
+}}}
+
+###############################################################################
diff --git a/performance-tests/Server_Concurrency/Leader_Follower/leader_follower.cpp b/performance-tests/Server_Concurrency/Leader_Follower/leader_follower.cpp new file mode 100644 index 00000000000..0e208c731a3 --- /dev/null +++ b/performance-tests/Server_Concurrency/Leader_Follower/leader_follower.cpp @@ -0,0 +1,261 @@ +// $Id$ + +#include "ace/Task.h" +#include "ace/Get_Opt.h" +#include "ace/High_Res_Timer.h" +#include "ace/Sched_Params.h" +#include "../Latency_Stats.h" + +static size_t number_of_messages = 100; +static size_t message_size = 100; +static size_t number_of_threads = 10; +static size_t burst_size = 10; +static size_t timeout_between_bursts = 1; +static size_t debug = 0; + +static size_t leader_available = 0; +static size_t messages_in_this_burst = 0; +static size_t total_messages_consumed = 0; +static size_t burst = 1; + +static ACE_hrtime_t start_of_burst; + +typedef ACE_Task<ACE_MT_SYNCH> TASK; + +class Leader_Follower_Task : public TASK +{ +public: + Leader_Follower_Task (ACE_SYNCH_MUTEX &mutex, + ACE_SYNCH_CONDITION &condition); + int svc (void); + + size_t messages_consumed_; + ACE_SYNCH_MUTEX &mutex_; + ACE_SYNCH_CONDITION &condition_; + + Latency_Stats stats_; +}; + +Leader_Follower_Task::Leader_Follower_Task (ACE_SYNCH_MUTEX &mutex, + ACE_SYNCH_CONDITION &condition) + : messages_consumed_ (0), + mutex_ (mutex), + condition_ (condition) +{ +} + +int +Leader_Follower_Task::svc (void) +{ + for (;;) + { + { + ACE_GUARD_RETURN (ACE_SYNCH_MUTEX, ace_mon, this->mutex_, -1); + + // Wait until there is no leader. + while (leader_available) + { + int result = this->condition_.wait (); + if (result == -1) + { + ACE_ERROR_RETURN ((LM_ERROR, + "Leader_Follower_Task::svc (%t) -> %p\n", + "wait error"), + -1); + } + } + + // I am the leader. + leader_available = 1; + + // + // We are letting go of the leader follower lock before going + // in the event loop. + // + } + + // + // It is ok to modify these shared variables without a lock + // since we are the only leader. + // + + int exit_loop = 0; + if (number_of_messages == 0) + { + exit_loop = 1; + } + else + { + if (messages_in_this_burst == burst_size) + { + ++burst; + messages_in_this_burst = 0; + ACE_OS::sleep (timeout_between_bursts); + } + + if (messages_in_this_burst == 0) + { + start_of_burst = ACE_OS::gethrtime (); + } + + --number_of_messages; + + // Burst counter. + ++messages_in_this_burst; + + // Global counter. + ++total_messages_consumed; + + // Local counter. + ++this->messages_consumed_; + + if (debug) + { + ACE_DEBUG ((LM_DEBUG, + "(%t) burst %d: message %d; overall message %d; message for this thread %d\n", + burst, + messages_in_this_burst, + total_messages_consumed, + this->messages_consumed_)); + } + } + + { + ACE_GUARD_RETURN (ACE_SYNCH_MUTEX, ace_mon, this->mutex_, -1); + + // I am no longer the leader. + leader_available = 0; + + // Wake up a follower. + this->condition_.signal (); + } + + // Record time to wake up follower. + this->stats_.sample (ACE_OS::gethrtime () - start_of_burst); + + if (exit_loop) + { + break; + } + else + { + // + // Process message here. + // + + for (int j = 0; j < message_size; ++j) + { + // Eat a little CPU + /* takes about 40.2 usecs on a 167 MHz Ultra2 */ + u_long n = 1279UL; + ACE::is_prime (n, 2, n / 2); + } + } + } + + return 0; +} + +static int +parse_args (int argc, ASYS_TCHAR *argv[]) +{ + ACE_Get_Opt get_opt (argc, argv, ASYS_TEXT ("m:s:w:b:t:d")); + int c; + + while ((c = get_opt ()) != -1) + { + switch (c) + { + case 'm': + number_of_messages = ACE_OS::atoi (get_opt.optarg); + break; + case 's': + message_size = ACE_OS::atoi (get_opt.optarg); + break; + case 'w': + number_of_threads = ACE_OS::atoi (get_opt.optarg); + break; + case 'b': + burst_size = ACE_OS::atoi (get_opt.optarg); + break; + case 't': + timeout_between_bursts = ACE_OS::atoi (get_opt.optarg); + break; + case 'd': + debug = 1; + break; + default: + ACE_ERROR_RETURN ((LM_ERROR, + "usage: %s\n" + "\t[-m number of messages]\n" + "\t[-s message size]\n" + "\t[-w number of threads]\n" + "\t[-b burst size]\n" + "\t[-t timeout between bursts]\n" + "\t[-d debug]\n", + argv[0]), + -1); + } + } + + return 0; +} + +int +main (int argc, ASYS_TCHAR *argv[]) +{ + move_to_rt_class (); + ACE_High_Res_Timer::calibrate (); + + int result = parse_args (argc, argv); + if (result != 0) + { + return result; + } + + ACE_SYNCH_MUTEX mutex; + ACE_SYNCH_CONDITION condition (mutex); + + // Leader Followers. + Leader_Follower_Task **leader_followers = 0; + ACE_NEW_RETURN (leader_followers, + Leader_Follower_Task *[number_of_threads], + -1); + + // Create and activate them. + size_t i; + for (i = 0; i < number_of_threads; ++i) + { + ACE_NEW_RETURN (leader_followers[i], + Leader_Follower_Task (mutex, + condition), + -1); + + // Activate the leader_followers. + result = leader_followers[i]->activate (THR_BOUND); + if (result != 0) + { + return result; + } + } + + // Wait for all threads to terminate. + result = ACE_Thread_Manager::instance ()->wait (); + + Latency_Stats latency; + for (i = 0; i < number_of_threads; ++i) + { + latency.accumulate (leader_followers[i]->stats_); + } + + ACE_DEBUG ((LM_DEBUG, "\nTotals:\n")); + latency.dump_results (argv[0], "latency"); + + for (i = 0; i < number_of_threads; ++i) + { + delete leader_followers[i]; + } + delete[] leader_followers; + + return result; +} diff --git a/performance-tests/Server_Concurrency/Queue_Based_Workers/workers.cpp b/performance-tests/Server_Concurrency/Queue_Based_Workers/workers.cpp index 4ff06e020bf..ad32b878b38 100644 --- a/performance-tests/Server_Concurrency/Queue_Based_Workers/workers.cpp +++ b/performance-tests/Server_Concurrency/Queue_Based_Workers/workers.cpp @@ -2,6 +2,9 @@ #include "ace/Task.h" #include "ace/Get_Opt.h" +#include "ace/High_Res_Timer.h" +#include "ace/Sched_Params.h" +#include "../Latency_Stats.h" static size_t number_of_messages = 100; static size_t message_size = 100; @@ -10,6 +13,24 @@ static size_t burst_size = 10; static size_t timeout_between_bursts = 1; static size_t debug = 0; +static ACE_Data_Block *data_block = 0; + +class Message_Block : public ACE_Message_Block +{ +public: + Message_Block (ACE_Data_Block *data_block, + ACE_hrtime_t start_of_burst); + + ACE_hrtime_t start_of_burst_; +}; + +Message_Block::Message_Block (ACE_Data_Block *data_block, + ACE_hrtime_t start_of_burst) + : ACE_Message_Block (data_block), + start_of_burst_ (start_of_burst) +{ +} + typedef ACE_Task<ACE_MT_SYNCH> TASK; class Worker_Task : public TASK @@ -20,6 +41,7 @@ public: size_t messages_dequeued_; + Latency_Stats stats_; }; class IO_Task : public TASK @@ -40,8 +62,8 @@ Worker_Task::svc (void) { for (;;) { - ACE_Message_Block *message_block = 0; - int result = this->getq (message_block); + ACE_Message_Block *mb = 0; + int result = this->getq (mb); if (result == -1) { ACE_ERROR_RETURN ((LM_ERROR, @@ -50,6 +72,12 @@ Worker_Task::svc (void) -1); } + Message_Block *message_block = + ACE_dynamic_cast (Message_Block *, mb); + + // Record arrival time. + this->stats_.sample (ACE_OS::gethrtime () - message_block->start_of_burst_); + ACE_Message_Block::ACE_Message_Type message_type = message_block->msg_type (); @@ -78,6 +106,18 @@ Worker_Task::svc (void) "(%t) dequeued its %d message\n", this->messages_dequeued_)); } + + // + // Process message here. + // + + for (int j = 0; j < message_size; ++j) + { + // Eat a little CPU + /* takes about 40.2 usecs on a 167 MHz Ultra2 */ + u_long n = 1279UL; + ACE::is_prime (n, 2, n / 2); + } } } @@ -99,13 +139,16 @@ IO_Task::svc (void) // Data messages. while (number_of_messages > 0) { + ACE_hrtime_t start_of_burst = ACE_OS::gethrtime (); + for (i = 1; i <= burst_size && number_of_messages > 0; ++i, --number_of_messages, ++messages_queued) { - ACE_Message_Block *message_block = 0; + Message_Block *message_block = 0; ACE_NEW_RETURN (message_block, - ACE_Message_Block (message_size), + Message_Block (data_block, + start_of_burst), -1); int result = this->putq (message_block); @@ -201,12 +244,26 @@ parse_args (int argc, ASYS_TCHAR *argv[]) int main (int argc, ASYS_TCHAR *argv[]) { + move_to_rt_class (); + ACE_High_Res_Timer::calibrate (); + int result = parse_args (argc, argv); if (result != 0) { return result; } + size_t i = 0; + + ACE_NEW_RETURN (data_block, + ACE_Data_Block, + -1); + + for (i = 0; i < number_of_messages; ++i) + { + data_block->duplicate (); + } + ACE_Message_Queue<ACE_MT_SYNCH> message_queue; // Workers. @@ -215,18 +272,38 @@ main (int argc, ASYS_TCHAR *argv[]) Worker_Task *[number_of_workers], -1); + int priority = + (ACE_Sched_Params::priority_min (ACE_SCHED_FIFO) + + ACE_Sched_Params::priority_max (ACE_SCHED_FIFO)) / 2; + priority = ACE_Sched_Params::next_priority (ACE_SCHED_FIFO, priority); + + long flags = THR_BOUND | THR_SCHED_FIFO; + // Create and activate them. - for (size_t i = 0; i < number_of_workers; ++i) + for (i = 0; i < number_of_workers; ++i) { ACE_NEW_RETURN (workers[i], Worker_Task (&message_queue), -1); // Activate the workers. - result = workers[i]->activate (THR_BOUND); + result = workers[i]->activate (flags, + 1, + 1, + priority); if (result != 0) { - return result; + flags = THR_BOUND; + priority = ACE_Sched_Params::priority_min (ACE_SCHED_OTHER, + ACE_SCOPE_THREAD); + result = workers[i]->activate (flags, + 1, + 1, + priority); + if (result != 0) + { + return result; + } } } @@ -243,7 +320,21 @@ main (int argc, ASYS_TCHAR *argv[]) // Wait for all threads to terminate. result = ACE_Thread_Manager::instance ()->wait (); + Latency_Stats latency; + for (i = 0; i < number_of_workers; ++i) + { + latency.accumulate (workers[i]->stats_); + } + + ACE_DEBUG ((LM_DEBUG, "\nTotals:\n")); + latency.dump_results (argv[0], "latency"); + + for (i = 0; i < number_of_workers; ++i) + { + delete workers[i]; + } delete[] workers; + delete data_block; return result; } diff --git a/performance-tests/Server_Concurrency/Server_Concurrency.dsw b/performance-tests/Server_Concurrency/Server_Concurrency.dsw new file mode 100644 index 00000000000..4ad03e67bff --- /dev/null +++ b/performance-tests/Server_Concurrency/Server_Concurrency.dsw @@ -0,0 +1,17 @@ +Microsoft Developer Studio Workspace File, Format Version 6.00
+# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!
+
+###############################################################################
+
+Global:
+
+Package=<5>
+{{{
+}}}
+
+Package=<3>
+{{{
+}}}
+
+###############################################################################
+
|