From cdb0aeb153abffbde1f921ac1eadce0eea41faf8 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Thu, 27 Feb 2014 10:47:17 -0800 Subject: [PATCH] some hacking on server performance --- .../src/octree/OctreeSendThread.cpp | 26 ++++++++++++++++--- assignment-client/src/octree/OctreeServer.cpp | 16 ++++++++++++ assignment-client/src/octree/OctreeServer.h | 5 ++++ libraries/octree/src/OctreePersistThread.cpp | 2 -- libraries/particles/src/ParticleTree.cpp | 2 ++ 5 files changed, 46 insertions(+), 5 deletions(-) diff --git a/assignment-client/src/octree/OctreeSendThread.cpp b/assignment-client/src/octree/OctreeSendThread.cpp index 121e80b808..b1f693725a 100644 --- a/assignment-client/src/octree/OctreeSendThread.cpp +++ b/assignment-client/src/octree/OctreeSendThread.cpp @@ -52,6 +52,8 @@ bool OctreeSendThread::process() { } node->getMutex().unlock(); // we're done with this node for now. + } else { + qDebug("OctreeSendThread::process() failed to get node lock"); } } } else { @@ -70,8 +72,8 @@ bool OctreeSendThread::process() { PerformanceWarning warn(false,"OctreeSendThread... usleep()",false,&_usleepTime,&_usleepCalls); usleep(usecToSleep); } else { - if (_myServer->wantsDebugSending() && _myServer->wantsVerboseDebug()) { - std::cout << "Last send took too much time, not sleeping!\n"; + if (true || (_myServer->wantsDebugSending() && _myServer->wantsVerboseDebug())) { + qDebug() << "Last send took too much time (" << (elapsed / USECS_PER_MSEC) <<" msecs), not sleeping!\n"; } } } @@ -420,9 +422,23 @@ int OctreeSendThread::packetDistributor(const SharedNodePointer& node, OctreeQue isFullScene, &nodeData->stats, _myServer->getJurisdiction()); + quint64 lockWaitStart = usecTimestampNow(); _myServer->getOctree()->lockForRead(); + quint64 lockWaitEnd = usecTimestampNow(); + int lockWaitElapsedMsec = (lockWaitEnd - lockWaitStart)/USECS_PER_MSEC; + if (lockWaitElapsedMsec > 0) { + qDebug() << "lockWaitElapsedMsec=" << lockWaitElapsedMsec; + } + nodeData->stats.encodeStarted(); + + quint64 encodeStart = usecTimestampNow(); bytesWritten = _myServer->getOctree()->encodeTreeBitstream(subTree, &_packetData, nodeData->nodeBag, params); + quint64 encodeEnd = usecTimestampNow(); + int encodeElapsedMsec = (encodeEnd - encodeStart)/USECS_PER_MSEC; + if (encodeElapsedMsec > 0) { + qDebug() << "encodeElapsedMsec=" << encodeElapsedMsec; + } // If after calling encodeTreeBitstream() there are no nodes left to send, then we know we've // sent the entire scene. We want to know this below so we'll actually write this content into @@ -543,7 +559,11 @@ int OctreeSendThread::packetDistributor(const SharedNodePointer& node, OctreeQue quint64 endCompressTimeMsecs = OctreePacketData::getCompressContentTime() / 1000; int elapsedCompressTimeMsecs = endCompressTimeMsecs - startCompressTimeMsecs; - + if (elapsedmsec > 0) { + qDebug() << "elapsedmsec=" << elapsedmsec; + } + OctreeServer::trackLoopTime((float)elapsedmsec); + if (elapsedmsec > 100) { if (elapsedmsec > 1000) { int elapsedsec = (end - start)/1000000; diff --git a/assignment-client/src/octree/OctreeServer.cpp b/assignment-client/src/octree/OctreeServer.cpp index 1fb858c884..c1dd5a69ec 100644 --- a/assignment-client/src/octree/OctreeServer.cpp +++ b/assignment-client/src/octree/OctreeServer.cpp @@ -19,6 +19,8 @@ #include "OctreeServerConsts.h" OctreeServer* OctreeServer::_instance = NULL; +int OctreeServer::_clientCount = 0; +SimpleMovingAverage OctreeServer::_averageLoopTime(1000); void OctreeServer::attachQueryNodeToNode(Node* newNode) { if (newNode->getLinkedData() == NULL) { @@ -48,6 +50,7 @@ OctreeServer::OctreeServer(const QByteArray& packet) : _startedUSecs(usecTimestampNow()) { _instance = this; + _averageLoopTime.updateAverage(0); } OctreeServer::~OctreeServer() { @@ -234,6 +237,19 @@ bool OctreeServer::handleHTTPRequest(HTTPConnection* connection, const QString& quint64 totalBytesOfColor = OctreePacketData::getTotalBytesOfColor(); const int COLUMN_WIDTH = 10; + statsString += QString(" Configured Max PPS/Client: %1 pps/client\r\n") + .arg(locale.toString((uint)getPacketsPerClientPerSecond()).rightJustified(COLUMN_WIDTH, ' ')); + statsString += QString(" Configured Max PPS/Server: %1 pps/server\r\n\r\n") + .arg(locale.toString((uint)getPacketsTotalPerSecond()).rightJustified(COLUMN_WIDTH, ' ')); + statsString += QString(" Total Clients Connected: %1 clients\r\n\r\n") + .arg(locale.toString((uint)getCurrentClientCount()).rightJustified(COLUMN_WIDTH, ' ')); + + float averageLoopTime = _averageLoopTime.getAverage(); + statsString += QString().sprintf(" Average packetLoop() time: %5.2f msecs\r\n", averageLoopTime); + + qDebug() << "_averageLoopTime.getAverage()=" << averageLoopTime; + + statsString += QString(" Total Outbound Packets: %1 packets\r\n") .arg(locale.toString((uint)totalOutboundPackets).rightJustified(COLUMN_WIDTH, ' ')); statsString += QString(" Total Outbound Bytes: %1 bytes\r\n") diff --git a/assignment-client/src/octree/OctreeServer.h b/assignment-client/src/octree/OctreeServer.h index e221011b76..5315934d6a 100644 --- a/assignment-client/src/octree/OctreeServer.h +++ b/assignment-client/src/octree/OctreeServer.h @@ -63,6 +63,8 @@ public: static void attachQueryNodeToNode(Node* newNode); + static void trackLoopTime(float time) { _averageLoopTime.updateAverage(time); } + bool handleHTTPRequest(HTTPConnection* connection, const QString& path); public slots: /// runs the voxel server assignment @@ -95,6 +97,9 @@ protected: time_t _started; quint64 _startedUSecs; + + static int _clientCount; + static SimpleMovingAverage _averageLoopTime; }; #endif // __octree_server__OctreeServer__ diff --git a/libraries/octree/src/OctreePersistThread.cpp b/libraries/octree/src/OctreePersistThread.cpp index c6c3ce2a6a..3de3085a36 100644 --- a/libraries/octree/src/OctreePersistThread.cpp +++ b/libraries/octree/src/OctreePersistThread.cpp @@ -68,9 +68,7 @@ bool OctreePersistThread::process() { usleep(USECS_TO_SLEEP); // do our updates then check to save... - _tree->lockForWrite(); _tree->update(); - _tree->unlock(); quint64 now = usecTimestampNow(); quint64 sinceLastSave = now - _lastCheck; diff --git a/libraries/particles/src/ParticleTree.cpp b/libraries/particles/src/ParticleTree.cpp index afffe7943c..b422b8e4e8 100644 --- a/libraries/particles/src/ParticleTree.cpp +++ b/libraries/particles/src/ParticleTree.cpp @@ -474,7 +474,9 @@ void ParticleTree::update() { AABox treeBounds = getRoot()->getAABox(); if (!shouldDie && treeBounds.contains(args._movingParticles[i].getPosition())) { + lockForWrite(); storeParticle(args._movingParticles[i]); + unlock(); } else { uint32_t particleID = args._movingParticles[i].getID(); quint64 deletedAt = usecTimestampNow();