Merge pull request #6004 from birarda/av-mixer-stats

add receive rate and inbound kbps to avatar-mixer stats
This commit is contained in:
Howard Stearns 2015-10-06 15:24:30 -07:00
commit e66f6b79cc
10 changed files with 36 additions and 25 deletions

View file

@ -262,14 +262,9 @@ void AvatarMixer::broadcastAvatarData() {
AvatarDataSequenceNumber lastSeqToReceiver = nodeData->getLastBroadcastSequenceNumber(otherNode->getUUID());
AvatarDataSequenceNumber lastSeqFromSender = otherNodeData->getLastReceivedSequenceNumber();
if (lastSeqToReceiver > lastSeqFromSender) {
// Did we somehow get out of order packets from the sender?
// We don't expect this to happen - in RELEASE we add this to a trackable stat
// and in DEBUG we crash on the assert
if (lastSeqToReceiver > lastSeqFromSender && lastSeqToReceiver != UINT16_MAX) {
// we got out out of order packets from the sender, track it
otherNodeData->incrementNumOutOfOrderSends();
assert(false);
}
// make sure we haven't already sent this data from this sender to this receiver
@ -485,10 +480,13 @@ void AvatarMixer::sendStatsPacket() {
QJsonObject avatarStats;
const QString NODE_OUTBOUND_KBPS_STAT_KEY = "outbound_kbps";
const QString NODE_INBOUND_KBPS_STAT_KEY = "inbound_kbps";
// add the key to ask the domain-server for a username replacement, if it has it
avatarStats[USERNAME_UUID_REPLACEMENT_STATS_KEY] = uuidStringWithoutCurlyBraces(node->getUUID());
avatarStats[NODE_OUTBOUND_KBPS_STAT_KEY] = node->getOutboundBandwidth();
avatarStats[NODE_INBOUND_KBPS_STAT_KEY] = node->getInboundBandwidth();
AvatarMixerClientData* clientData = static_cast<AvatarMixerClientData*>(node->getLinkedData());
if (clientData) {

View file

@ -40,11 +40,14 @@ uint16_t AvatarMixerClientData::getLastBroadcastSequenceNumber(const QUuid& node
void AvatarMixerClientData::loadJSONStats(QJsonObject& jsonObject) const {
jsonObject["display_name"] = _avatar.getDisplayName();
jsonObject["full_rate_distance"] = _fullRateDistance;
jsonObject["max_avatar_distance"] = _maxAvatarDistance;
jsonObject["num_avatars_sent_last_frame"] = _numAvatarsSentLastFrame;
jsonObject["avg_other_avatar_starves_per_second"] = getAvgNumOtherAvatarStarvesPerSecond();
jsonObject["avg_other_avatar_skips_per_second"] = getAvgNumOtherAvatarSkipsPerSecond();
jsonObject["max_av_distance"] = _maxAvatarDistance;
jsonObject["num_avs_sent_last_frame"] = _numAvatarsSentLastFrame;
jsonObject["avg_other_av_starves_per_second"] = getAvgNumOtherAvatarStarvesPerSecond();
jsonObject["avg_other_av_skips_per_second"] = getAvgNumOtherAvatarSkipsPerSecond();
jsonObject["total_num_out_of_order_sends"] = _numOutOfOrderSends;
jsonObject[OUTBOUND_AVATAR_DATA_STATS_KEY] = getOutboundAvatarDataKbps();
jsonObject[INBOUND_AVATAR_DATA_STATS_KEY] = _avatar.getAverageBytesReceivedPerSecond() / (float) BYTES_PER_KILOBIT;
jsonObject["av_data_receive_rate"] = _avatar.getReceiveRate();
}

View file

@ -27,6 +27,7 @@
#include <UUIDHasher.h>
const QString OUTBOUND_AVATAR_DATA_STATS_KEY = "outbound_av_data_kbps";
const QString INBOUND_AVATAR_DATA_STATS_KEY = "inbound_av_data_kbps";
class AvatarMixerClientData : public NodeData {
Q_OBJECT

View file

@ -274,10 +274,14 @@ void LimitedNodeList::fillPacketHeader(const NLPacket& packet, const QUuid& conn
qint64 LimitedNodeList::sendUnreliablePacket(const NLPacket& packet, const Node& destinationNode) {
Q_ASSERT(!packet.isPartOfMessage());
if (!destinationNode.getActiveSocket()) {
return 0;
}
emit dataSent(destinationNode.getType(), packet.getDataSize());
destinationNode.recordBytesSent(packet.getDataSize());
return sendUnreliablePacket(packet, *destinationNode.getActiveSocket(), destinationNode.getConnectionSecret());
}
@ -298,7 +302,10 @@ qint64 LimitedNodeList::sendPacket(std::unique_ptr<NLPacket> packet, const Node&
if (!destinationNode.getActiveSocket()) {
return 0;
}
emit dataSent(destinationNode.getType(), packet->getDataSize());
destinationNode.recordBytesSent(packet->getDataSize());
return sendPacket(std::move(packet), *destinationNode.getActiveSocket(), destinationNode.getConnectionSecret());
}

View file

@ -232,22 +232,22 @@ BandwidthRecorder& getBandwidthRecorder(const QUuid & uuid) {
return *PEER_BANDWIDTH[uuid].data();
}
void NetworkPeer::recordBytesSent(int count) {
void NetworkPeer::recordBytesSent(int count) const {
auto& bw = getBandwidthRecorder(_uuid);
bw.updateOutboundData(0, count);
}
void NetworkPeer::recordBytesReceived(int count) {
void NetworkPeer::recordBytesReceived(int count) const {
auto& bw = getBandwidthRecorder(_uuid);
bw.updateInboundData(0, count);
}
float NetworkPeer::getOutboundBandwidth() {
float NetworkPeer::getOutboundBandwidth() const {
auto& bw = getBandwidthRecorder(_uuid);
return bw.getAverageOutputKilobitsPerSecond(0);
}
float NetworkPeer::getInboundBandwidth() {
float NetworkPeer::getInboundBandwidth() const {
auto& bw = getBandwidthRecorder(_uuid);
return bw.getAverageInputKilobitsPerSecond(0);
}

View file

@ -70,11 +70,11 @@ public:
void incrementConnectionAttempts() { ++_connectionAttempts; }
void resetConnectionAttempts() { _connectionAttempts = 0; }
void recordBytesSent(int count);
void recordBytesReceived(int count);
void recordBytesSent(int count) const;
void recordBytesReceived(int count) const;
float getOutboundBandwidth(); // in kbps
float getInboundBandwidth(); // in kbps
float getOutboundBandwidth() const; // in kbps
float getInboundBandwidth() const; // in kbps
friend QDataStream& operator<<(QDataStream& out, const NetworkPeer& peer);
friend QDataStream& operator>>(QDataStream& in, NetworkPeer& peer);

View file

@ -404,6 +404,8 @@ void PacketReceiver::handleVerifiedPacket(std::unique_ptr<udt::Packet> packet) {
if (matchingNode) {
emit dataReceived(matchingNode->getType(), nlPacket->getDataSize());
matchingNode->recordBytesReceived(nlPacket->getDataSize());
QMetaMethod metaMethod = listener.second;
static const QByteArray QSHAREDPOINTER_NODE_NORMALIZED = QMetaObject::normalizedType("QSharedPointer<Node>");

View file

@ -126,10 +126,6 @@ BasePacket& BasePacket::operator=(BasePacket&& other) {
return *this;
}
qint64 BasePacket::getDataSize() const {
return (_payloadStart - _packet.get()) + _payloadSize;
}
void BasePacket::setPayloadSize(qint64 payloadSize) {
if (isWritable()) {
Q_ASSERT(payloadSize <= _payloadCapacity);

View file

@ -48,7 +48,10 @@ public:
const char* getData() const { return _packet.get(); }
// Returns the size of the packet, including the header
qint64 getDataSize() const;
qint64 getDataSize() const { return (_payloadStart - _packet.get()) + _payloadSize; }
// Returns the size of the packet, including the header AND the UDP/IP header
qint64 getWireSize() const { return getDataSize() + UDP_IPV4_HEADER_SIZE; }
// Returns the size of the payload only
qint64 getPayloadSize() const { return _payloadSize; }

View file

@ -17,8 +17,9 @@
#include "SequenceNumber.h"
namespace udt {
static const int UDP_IPV4_HEADER_SIZE = 28;
static const int MAX_PACKET_SIZE_WITH_UDP_HEADER = 1500;
static const int MAX_PACKET_SIZE = MAX_PACKET_SIZE_WITH_UDP_HEADER - 28;
static const int MAX_PACKET_SIZE = MAX_PACKET_SIZE_WITH_UDP_HEADER - UDP_IPV4_HEADER_SIZE;
static const int MAX_PACKETS_IN_FLIGHT = 25600;
static const int CONNECTION_RECEIVE_BUFFER_SIZE_PACKETS = 8192;
static const int CONNECTION_SEND_BUFFER_SIZE_PACKETS = 8192;