Browse Source

PushAsync函数逻辑

lixioayao 5 years ago
parent
commit
24881b36ee
1 changed files with 19 additions and 20 deletions
  1. 19 20
      db/db_api/CDBConnPool.cpp

+ 19 - 20
db/db_api/CDBConnPool.cpp

@@ -1,5 +1,6 @@
 #include "CDBConnPool.h"
 #include <boost/bind.hpp>
+#include <thread>
 #include <log.h>
 
 namespace YADB
@@ -253,28 +254,26 @@ namespace YADB
 
 	void CDBConnPool::_AsyncThreadFunc( CDBConnPool* pOwner )
 	{
-		uint64_t cc=0;
+		//uint64_t cc=0;
 		while( pOwner->__Running )
 		{
-			std::vector<_ASYNC_SQL_*> sql_list;
-			sql_list.reserve(1<<15);
-
-			{
-				std::unique_lock<std::mutex> lock(g_mutex);
-				sql_list.swap(g_sql_list);
-			}
-
-			if(++cc % 100 == 0)//100ms 输出一次
-			{
-				logn_info(2,"sql_list size=%lld", sql_list.size());
-			}
-
-			for(auto pData:sql_list)
-			{
-				ExecAsyncSql(pData);
-			}
-
-			boost::this_thread::sleep_for( boost::chrono::milliseconds( 1 ) );
+            if(!g_sql_list.empty()){
+		    	std::vector<_ASYNC_SQL_*> sql_list;
+		    	sql_list.reserve(1<<15);
+                
+		    	{
+		    		std::unique_lock<std::mutex> lock(g_mutex);
+		    		sql_list.swap(g_sql_list);
+		    	}
+
+                //100ms太理想了。上下井高峰期这个有可能1h都没一条日志
+		    	//if(++cc % 100 == 0)//100ms 输出一次
+		    	logn_info(2,"sql_list size=%lld", sql_list.size());
+                //1条链接处理sql。sql堆积。速度慢 
+		    	for(auto pData:sql_list)
+		    		ExecAsyncSql(pData);
+            }
+			std::this_thread::sleep_for(std::chrono::milliseconds(1));
 		}
 
 		//线程退出