You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by sw...@apache.org on 2024/04/30 00:48:12 UTC

(logging-log4cxx) branch master updated: Improve AsyncAppender throughput (#377)

This is an automated email from the ASF dual-hosted git repository.

swebb2066 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/logging-log4cxx.git


The following commit(s) were added to refs/heads/master by this push:
     new e74b2a85 Improve AsyncAppender throughput (#377)
e74b2a85 is described below

commit e74b2a85a709800b485485c478eb5b172eaca082
Author: Stephen Webb <st...@ieee.org>
AuthorDate: Tue Apr 30 10:48:07 2024 +1000

    Improve AsyncAppender throughput (#377)
---
 src/main/cpp/asyncappender.cpp | 33 ++++++++++++++++++---------------
 1 file changed, 18 insertions(+), 15 deletions(-)

diff --git a/src/main/cpp/asyncappender.cpp b/src/main/cpp/asyncappender.cpp
index 1e019155..7cc0f9f5 100644
--- a/src/main/cpp/asyncappender.cpp
+++ b/src/main/cpp/asyncappender.cpp
@@ -297,6 +297,7 @@ void AsyncAppender::append(const spi::LoggingEventPtr& event, Pool& p)
 			priv->bufferNotEmpty.notify_all();
 			break;
 		}
+		priv->bufferNotEmpty.notify_all();
 		//
 		//   Following code is only reachable if buffer is full or eventCount has overflowed
 		//
@@ -506,32 +507,34 @@ void AsyncAppender::dispatch()
 		Pool p;
 		LoggingEventList events;
 		events.reserve(priv->bufferSize);
-		//
-		//   process events after lock on buffer is released.
-		//
+		for (int count = 0; count < 2 && priv->dispatchedCount == priv->commitCount; ++count)
+			std::this_thread::yield(); // Wait a bit
+		if (priv->dispatchedCount == priv->commitCount)
 		{
 			std::unique_lock<std::mutex> lock(priv->bufferMutex);
 			priv->bufferNotEmpty.wait(lock, [this]() -> bool
 				{ return priv->dispatchedCount != priv->commitCount || priv->closed; }
 			);
-			isActive = !priv->closed;
+		}
+		isActive = !priv->closed;
 
-			while (events.size() < priv->bufferSize && priv->dispatchedCount != priv->commitCount)
-			{
-				auto index = priv->dispatchedCount % priv->buffer.size();
-				const auto& data = priv->buffer[index];
-				events.push_back(data.event);
-				if (data.pendingCount < pendingCountHistogram.size())
-					++pendingCountHistogram[data.pendingCount];
-				++priv->dispatchedCount;
-			}
+		while (events.size() < priv->bufferSize && priv->dispatchedCount != priv->commitCount)
+		{
+			auto index = priv->dispatchedCount % priv->buffer.size();
+			const auto& data = priv->buffer[index];
+			events.push_back(data.event);
+			if (data.pendingCount < pendingCountHistogram.size())
+				++pendingCountHistogram[data.pendingCount];
+			++priv->dispatchedCount;
+		}
+		priv->bufferNotFull.notify_all();
+		{
+			std::lock_guard<std::mutex> lock(priv->bufferMutex);
 			for (auto discardItem : priv->discardMap)
 			{
 				events.push_back(discardItem.second.createEvent(p));
 			}
-
 			priv->discardMap.clear();
-			priv->bufferNotFull.notify_all();
 		}
 
 		for (auto item : events)