support pstats-tcp-ratio, tcp by default

This commit is contained in:
David Rose 2004-09-03 19:22:22 +00:00
parent 92b9f2e8da
commit 3706822aae
4 changed files with 54 additions and 2 deletions

View File

@ -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

View File

@ -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();

View File

@ -28,6 +28,8 @@
#include "pStatThread.h"
#include "config_pstats.h"
#include "pStatProperties.h"
#include "cmath.h"
#include "mathNumbers.h"
#include <algorithm>
@ -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);

View File

@ -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;