# ------------------------------------------------------------ # Copyright (c) 2016-2017 # Q.W.Page Associates Inc. # www.qwpage.com # All rights reserved. # ------------------------------------------------------------ /* { Server side message statistics accumulates the number of messages of various sizes. This class exists only because we have both a server and service_hub and either this code is written twice, or we cut it out and share it. So this file exists because we share it. */ } /* { Communication volume collection ------------------------------- Plug/Socket Usage ----------------- Updates server/service_hub usage continuously. So don't need deltas hers. It's as if we increment and send the deltas at the same time. server/service_hub Usage ------------------------ Keeps rbs and deltas. When updates mothership, sends and resets deltas. Mothership/crm -------------- For now just collects messages. Later will update customer rbs with the deltas received. Can accumulate messages in crm database. Rules of Thumb -------------- Each level maintains deltas and rbs. Level A only updates level B with deltas, and resets deltas when it does so. We really only need compressed numbers. Therefore we will have byte_count and uncompressed_byte_count. Don't need adjective in compressed_byte_count. When do we update the mothership? Why not piggyback messages on connection_create? Must also send before the server/service_hub shuts down. We can gather the usage on the server and service_hub. Yes that means twice. Maybe we should move this stuff into server and service_hub also. What the heck. Each plug and socket accumulates usage. If it updates global usage, should it reset? It makes sense that we should send deltas only. When do we send usage to the mothership? Do we reset usage when sent? Where do we store usage? (1) Send volumes to mothership. (2) Resolution possibilities - per application database - per server/service - per connection Problem - messages are compressed - the only way we know the compressed bytes is low level - perhaps we could collect at the relay point and collect globally - we could track compressed and uncompressed - we could track per connection because we have the socket address We start by collecting for ever cpp plug and socket. */ } ::itcl::class ::qw::server_side_message_statistics { protected variable _up_message_count_array; # index is message size, value is message count. protected variable _down_message_count_array; # index is message size, value is message count. protected variable _message_size_list ""; method constructor {} { ::set _message_size_list { 64 128 256 512 1024 2048 4096 8192 16384 32768 65536 131072 262144 524288 1048576 4294967296 } message_statistics_reset; } method destructor {} { ::set rwb1_debug 0; ::if {$rwb1_debug} {::puts "rwb1_debug,server_connection_manager,destructor,1000.0";} } method message_statistics_update {sargs} { # ::qw::server_side_message_statistics::singleton server_side_message_statistics_update .up_message_bytes $UpByteCount .down_message_bytes $DownByeCount; ::set rwb1_debug 0; ::if {$rwb1_debug} {::puts "rwb1_debug,message_statistics_update,1000.00,sargs==$sargs";} ::set UpMessageSize [::sargs::integer_get $sargs .up_message_size]; ::if {$UpMessageSize!=0} { ::foreach Size $_message_size_list { ::if {$Size>$UpMessageSize} { ::incr _up_message_count_array($Size) 1; ::break; } } } ::set DownMessageSize [::sargs::integer_get $sargs .down_message_size]; ::if {$DownMessageSize!=0} { ::foreach Size $_message_size_list { ::if {$Size>$DownMessageSize} { ::incr _down_message_count_array($Size) 1; ::break; } } } ::if {$rwb1_debug} {::puts "rwb1_debug,message_statistics_update,1000.99";} } method message_statistics_reset {sargs} { /* { We reset the statistics to zero so we can start collecting them again for a presumably different operation. */ } ::foreach Size $_message_size_list { ::set _up_message_count_array($Size) 0; ::set _down_message_count_array($Size) 0; } } method message_statistics_get {} { ::set rwb1_debug 0; ::if {$rwb1_debug} {::puts "rwb1_debug,message_statistics_get,1000.0";} ::set RecordList [::list]; ::set RecordCount 0; ::foreach MessageSize $_message_size_list { ::set UpMessageCount 0; ::if {[::info exists _up_message_count_array($MessageSize)]} { ::set UpMessageCount $_up_message_count_array($MessageSize); } ::set DownMessageCount 0; ::if {[::info exists _down_message_count_array($MessageSize)]} { ::set DownMessageCount $_down_message_count_array($MessageSize); } ::lappend RecordList [::sargs .record_count $RecordCount .size $MessageSize .up_message_count $UpMessageCount .down_message_count $DownMessageCount]; ::incr RecordCount 1; } ::return [::sargs .message_statistics_record_list $RecordList]; } } ::qw::server_side_message_statistics ::qw::server_side_message_statistics::singleton;