From 3706822aaeadb27d55297a3a90668323576b6329 Mon Sep 17 00:00:00 2001 From: David Rose Date: Fri, 3 Sep 2004 19:22:22 +0000 Subject: [PATCH] support pstats-tcp-ratio, tcp by default --- panda/src/pstatclient/config_pstats.cxx | 6 ++++ panda/src/pstatclient/config_pstats.h | 1 + panda/src/pstatclient/pStatClient.cxx | 44 +++++++++++++++++++++++-- panda/src/pstatclient/pStatClient.h | 5 +++ 4 files changed, 54 insertions(+), 2 deletions(-) diff --git a/panda/src/pstatclient/config_pstats.cxx b/panda/src/pstatclient/config_pstats.cxx index 44049329cc..4c966a3ab8 100644 --- a/panda/src/pstatclient/config_pstats.cxx +++ b/panda/src/pstatclient/config_pstats.cxx @@ -46,6 +46,12 @@ const float pstats_history = config_pstats.GetFloat("pstats-history", 60.0); const float pstats_average_time = config_pstats.GetFloat("pstats-average-time", 3.0); const bool pstats_threaded_write = config_pstats.GetBool("pstats-threaded-write", false); +// This specifies the ratio of frame update messages that are eligible +// for UDP that are sent via TCP instead. It does not count messages +// that are too large for UDP and must be sent via TCP anyway. 1.0 +// means all messages are sent TCP; 0.0 means are are sent UDP. +const float pstats_tcp_ratio = config_pstats.GetFloat("pstats-tcp-ratio", 1.0); + //////////////////////////////////////////////////////////////////// // Function: init_libpstatclient // Description: Initializes the library. This must be called at diff --git a/panda/src/pstatclient/config_pstats.h b/panda/src/pstatclient/config_pstats.h index 782c20b144..4c4d082c5e 100644 --- a/panda/src/pstatclient/config_pstats.h +++ b/panda/src/pstatclient/config_pstats.h @@ -40,6 +40,7 @@ extern EXPCL_PANDA const float pstats_history; extern EXPCL_PANDA const float pstats_average_time; extern EXPCL_PANDA const bool pstats_threaded_write; +extern EXPCL_PANDA const float pstats_tcp_ratio; extern EXPCL_PANDA void init_libpstatclient(); diff --git a/panda/src/pstatclient/pStatClient.cxx b/panda/src/pstatclient/pStatClient.cxx index 10c2d44923..6acd41781d 100644 --- a/panda/src/pstatclient/pStatClient.cxx +++ b/panda/src/pstatclient/pStatClient.cxx @@ -28,6 +28,8 @@ #include "pStatThread.h" #include "config_pstats.h" #include "pStatProperties.h" +#include "cmath.h" +#include "mathNumbers.h" #include @@ -90,6 +92,23 @@ PStatClient() : _client_name = get_pstats_name(); _max_rate = get_pstats_max_rate(); + + _tcp_count = 1; + _udp_count = 1; + + if (pstats_tcp_ratio >= 1.0f) { + _tcp_count_factor = 0.0f; + _udp_count_factor = 1.0f; + + } else if (pstats_tcp_ratio <= 0.0f) { + _tcp_count_factor = 1.0f; + _udp_count_factor = 0.0f; + + } else { + csincos(pstats_tcp_ratio * MathNumbers::pi_f / 2.0f, + &_udp_count_factor, + &_tcp_count_factor); + } } //////////////////////////////////////////////////////////////////// @@ -856,8 +875,29 @@ transmit_frame_data(int thread_index) { _threads[thread_index]._frame_data.write_datagram(datagram); if (_writer.is_valid_for_udp(datagram)) { - nassertv(_got_udp_port); - _writer.send(datagram, _udp_connection, _server); + if (_udp_count * _udp_count_factor < _tcp_count * _tcp_count_factor) { + // Send this one as a UDP packet. + nassertv(_got_udp_port); + _writer.send(datagram, _udp_connection, _server); + _udp_count++; + + if (_udp_count == 0) { + // Wraparound! + _udp_count = 1; + _tcp_count = 1; + } + + } else { + // Send this one as a TCP packet. + _writer.send(datagram, _tcp_connection); + _tcp_count++; + + if (_tcp_count == 0) { + // Wraparound! + _udp_count = 1; + _tcp_count = 1; + } + } } else { _writer.send(datagram, _tcp_connection); diff --git a/panda/src/pstatclient/pStatClient.h b/panda/src/pstatclient/pStatClient.h index 8e4d841ab9..54448b6981 100644 --- a/panda/src/pstatclient/pStatClient.h +++ b/panda/src/pstatclient/pStatClient.h @@ -195,6 +195,11 @@ private: string _client_name; float _max_rate; + float _tcp_count_factor; + float _udp_count_factor; + unsigned int _tcp_count; + unsigned int _udp_count; + static PStatClient *_global_pstats; friend class PStatCollector; friend class PStatThread;