optimizing performance issues under large-scale connection
diff --git a/lib/cpp/src/thrift/server/TNonblockingServer.cpp b/lib/cpp/src/thrift/server/TNonblockingServer.cpp
index ae92da3..d53535b 100644
--- a/lib/cpp/src/thrift/server/TNonblockingServer.cpp
+++ b/lib/cpp/src/thrift/server/TNonblockingServer.cpp
@@ -886,8 +886,8 @@
 
 TNonblockingServer::~TNonblockingServer() {
   // Close any active connections (moves them to the idle connection stack)
-  while (activeConnections_.size()) {
-    activeConnections_.front()->close();
+  while (!activeConnections_.empty()) {
+    (*activeConnections_.begin())->close();
   }
   // Clean up unused TConnection objects in connectionStack_
   while (!connectionStack_.empty()) {
@@ -931,7 +931,8 @@
     result->setSocket(socket);
     result->init(ioThread);
   }
-  activeConnections_.push_back(result);
+
+  activeConnections_.insert(result);
   return result;
 }
 
@@ -941,11 +942,7 @@
 void TNonblockingServer::returnConnection(TConnection* connection) {
   Guard g(connMutex_);
 
-  activeConnections_.erase(std::remove(activeConnections_.begin(),
-                                       activeConnections_.end(),
-                                       connection),
-                           activeConnections_.end());
-
+  activeConnections_.erase(connection);
   if (connectionStackLimit_ && (connectionStack_.size() >= connectionStackLimit_)) {
     delete connection;
     --numTConnections_;