Only increase/decrease rate when we want to send more/have sent more than the

minimum, respectively.
This commit is contained in:
Andrzej Kapolka 2014-06-25 16:56:02 -07:00
parent 705445ce62
commit 5effcd24ff
3 changed files with 31 additions and 5 deletions

View file

@ -79,11 +79,30 @@ ReliableChannel* DatagramSequencer::getReliableInputChannel(int index) {
return channel; return channel;
} }
int DatagramSequencer::startPacketGroup() { int DatagramSequencer::startPacketGroup(int desiredPackets) {
// figure out how much data we have enqueued and increase the number of packets desired
int totalAvailable = 0;
foreach (ReliableChannel* channel, _reliableOutputChannels) {
totalAvailable += channel->getBytesAvailable();
}
desiredPackets += (totalAvailable / _maxPacketSize);
// increment our packet counter and subtract/return the integer portion // increment our packet counter and subtract/return the integer portion
_packetsToWrite += _packetsPerGroup; _packetsToWrite += _packetsPerGroup;
int wholePackets = (int)_packetsToWrite; int wholePackets = (int)_packetsToWrite;
_packetsToWrite -= wholePackets; _packetsToWrite -= wholePackets;
wholePackets = qMin(wholePackets, desiredPackets);
// if we don't want to send any more, push out the rate increase number past the group
if (desiredPackets <= _packetsPerGroup) {
_packetRateIncreasePacketNumber = _outgoingPacketNumber + wholePackets + 1;
}
// likewise, if we're only sending one packet, don't let its loss cause rate decrease
if (wholePackets == 1) {
_packetRateDecreasePacketNumber = _outgoingPacketNumber + 2;
}
return wholePackets; return wholePackets;
} }

View file

@ -100,8 +100,9 @@ public:
ReliableChannel* getReliableInputChannel(int index = 0); ReliableChannel* getReliableInputChannel(int index = 0);
/// Starts a packet group. /// Starts a packet group.
/// \param desiredPackets the number of packets we'd like to write in the group
/// \return the number of packets to write in the group /// \return the number of packets to write in the group
int startPacketGroup(); int startPacketGroup(int desiredPackets = 1);
/// Starts a new packet for transmission. /// Starts a new packet for transmission.
/// \return a reference to the Bitstream to use for writing to the packet /// \return a reference to the Bitstream to use for writing to the packet

View file

@ -147,6 +147,8 @@ static int bytesSent = 0;
static int bytesReceived = 0; static int bytesReceived = 0;
static int maxDatagramsPerPacket = 0; static int maxDatagramsPerPacket = 0;
static int maxBytesPerPacket = 0; static int maxBytesPerPacket = 0;
static int groupsSent = 0;
static int maxPacketsPerGroup = 0;
static int highPriorityMessagesSent = 0; static int highPriorityMessagesSent = 0;
static int highPriorityMessagesReceived = 0; static int highPriorityMessagesReceived = 0;
static int unreliableMessagesSent = 0; static int unreliableMessagesSent = 0;
@ -508,10 +510,12 @@ bool MetavoxelTests::run() {
} }
qDebug() << "Sent" << streamedBytesSent << "streamed bytes, received" << streamedBytesReceived; qDebug() << "Sent" << streamedBytesSent << "streamed bytes, received" << streamedBytesReceived;
qDebug() << "Sent" << datagramsSent << "datagrams with" << bytesSent << "bytes, received" << qDebug() << "Sent" << datagramsSent << "datagrams in" << groupsSent << "groups with" << bytesSent <<
datagramsReceived << "with" << bytesReceived << "bytes"; "bytes, received" << datagramsReceived << "with" << bytesReceived << "bytes";
qDebug() << "Max" << maxDatagramsPerPacket << "datagrams," << maxBytesPerPacket << "bytes per packet"; qDebug() << "Max" << maxDatagramsPerPacket << "datagrams," << maxBytesPerPacket << "bytes per packet";
qDebug() << "Average" << (bytesReceived / datagramsReceived) << "bytes per datagram"; qDebug() << "Max" << maxPacketsPerGroup << "packets per group";
qDebug() << "Average" << (bytesReceived / datagramsReceived) << "bytes per datagram," <<
(datagramsSent / groupsSent) << "datagrams per group";
qDebug() << "Speed:" << (bytesReceived / SIMULATION_ITERATIONS) << "bytes per iteration"; qDebug() << "Speed:" << (bytesReceived / SIMULATION_ITERATIONS) << "bytes per iteration";
qDebug() << "Efficiency:" << ((float)streamedBytesReceived / bytesReceived); qDebug() << "Efficiency:" << ((float)streamedBytesReceived / bytesReceived);
} }
@ -821,6 +825,8 @@ bool Endpoint::simulate(int iterationNumber) {
_remainingPipelineCapacity += datagram.size(); _remainingPipelineCapacity += datagram.size();
} }
int packetCount = _sequencer->startPacketGroup(); int packetCount = _sequencer->startPacketGroup();
groupsSent++;
maxPacketsPerGroup = qMax(maxPacketsPerGroup, packetCount);
for (int i = 0; i < packetCount; i++) { for (int i = 0; i < packetCount; i++) {
oldDatagramsSent = datagramsSent; oldDatagramsSent = datagramsSent;
oldBytesSent = bytesSent; oldBytesSent = bytesSent;