logging-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rgo...@apache.org
Subject svn commit: r1508572 - in /logging/log4j/log4j2/trunk: flume-ng/src/main/java/org/apache/logging/log4j/flume/appender/ samples/flume-common/src/main/java/org/apache/logging/log4j/samples/app/ src/changes/
Date Tue, 30 Jul 2013 18:20:26 GMT
Author: rgoers
Date: Tue Jul 30 18:20:26 2013
New Revision: 1508572

URL: http://svn.apache.org/r1508572
Log:
LOG4J2-328 - FlumePersistentManager was calling Berkeley DB's count method too frequently

Modified:
    logging/log4j/log4j2/trunk/flume-ng/src/main/java/org/apache/logging/log4j/flume/appender/FlumePersistentManager.java
    logging/log4j/log4j2/trunk/samples/flume-common/src/main/java/org/apache/logging/log4j/samples/app/LoggingController.java
    logging/log4j/log4j2/trunk/src/changes/changes.xml

Modified: logging/log4j/log4j2/trunk/flume-ng/src/main/java/org/apache/logging/log4j/flume/appender/FlumePersistentManager.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/flume-ng/src/main/java/org/apache/logging/log4j/flume/appender/FlumePersistentManager.java?rev=1508572&r1=1508571&r2=1508572&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/flume-ng/src/main/java/org/apache/logging/log4j/flume/appender/FlumePersistentManager.java
(original)
+++ logging/log4j/log4j2/trunk/flume-ng/src/main/java/org/apache/logging/log4j/flume/appender/FlumePersistentManager.java
Tue Jul 30 18:20:26 2013
@@ -437,7 +437,8 @@ public class FlumePersistentManager exte
             long nextBatch = System.currentTimeMillis() + manager.delay;
             while (!shutdown) {
                 long now = System.currentTimeMillis();
-                if (database.count() >= batchSize || (database.count() > 0 &&
nextBatch < now)) {
+                long dbCount = database.count();
+                if (dbCount >= batchSize || (dbCount > 0 && nextBatch <
now)) {
                     nextBatch = now + manager.delay;
                     try {
                         boolean errors = false;
@@ -546,7 +547,7 @@ public class FlumePersistentManager exte
                         LOGGER.warn("WriterThread encountered an exception. Continuing.",
ex);
                     }
                 } else {
-                    while (!shutdown && (database.count() == 0 || database.count()
< batchSize && nextBatch > now)) {
+                    while (!shutdown && (dbCount == 0 || dbCount < batchSize &&
nextBatch > now)) {
                         try {
                             final long interval = nextBatch - now;
                             gate.waitForOpen(interval, TimeUnit.MILLISECONDS);
@@ -557,7 +558,8 @@ public class FlumePersistentManager exte
                             break;
                         }
                         now = System.currentTimeMillis();
-                        if (database.count() == 0) {
+                        dbCount = database.count();
+                        if (!gate.isSignalled()) {
                             nextBatch = now + manager.delay;
                         }
                     }

Modified: logging/log4j/log4j2/trunk/samples/flume-common/src/main/java/org/apache/logging/log4j/samples/app/LoggingController.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/samples/flume-common/src/main/java/org/apache/logging/log4j/samples/app/LoggingController.java?rev=1508572&r1=1508571&r2=1508572&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/samples/flume-common/src/main/java/org/apache/logging/log4j/samples/app/LoggingController.java
(original)
+++ logging/log4j/log4j2/trunk/samples/flume-common/src/main/java/org/apache/logging/log4j/samples/app/LoggingController.java
Tue Jul 30 18:20:26 2013
@@ -49,13 +49,30 @@ public class LoggingController {
     private final Random ran = new Random();
 
     private List<AuditEvent> events;
+    private int timeBase = 1000;
 
     @RequestMapping(value = "/start.do", method = RequestMethod.GET)
     public ModelAndView startLogging(
         @RequestParam(value = "member", required = false, defaultValue = "fakemember") final
String member,
+        @RequestParam(value = "interval", required = false, defaultValue = "1000") final
String interval,
+        @RequestParam(value = "threads", required = false, defaultValue = "1") final String
threadCount,
                       final HttpServletRequest servletRequest) {
-
-        System.out.println("STARTING..................");
+        int numThreads = 1;
+        if (threadCount != null && threadCount.length() > 0) {
+            try {
+                numThreads = Integer.parseInt(threadCount);
+            } catch (Exception ex) {
+                System.out.println("Invalid threadCount specified: " + threadCount);
+            }
+        }
+        if (interval != null && interval.length() > 0) {
+            try {
+                timeBase = Integer.parseInt(interval);
+            } catch (Exception ex) {
+                System.out.println("Invalid interval specified: " + interval);
+            }
+        }
+        System.out.println("STARTING - Using " + numThreads + " threads at interval: " +
timeBase);
 
         if (events == null) {
             events = MockEventsSupplier.getAllEvents(member);
@@ -63,52 +80,54 @@ public class LoggingController {
 
         generateLog = true;
 
-        (new Thread() {
+        for (int i = 0; i < numThreads; ++i) {
+            (new Thread() {
 
-            @Override
-            public void run() {
-                ThreadContext.clear();
-
-                RequestContext.setSessionId("session1234");
-                RequestContext.setIpAddress("127.0.0.1");
-                RequestContext.setClientId("02121");
-                RequestContext.setProductName("IB");
-                RequestContext.setProductVersion("4.18.1");
-                RequestContext.setLocale("en_US");
-                RequestContext.setRegion("prod");
-                while (generateLog) {
-                    // Generate rand number between 1 to 10
-                    final int rand = ran.nextInt(9) + 1;
-
-                    // Sleep for rand seconds
-                    try {
-                        Thread.sleep(rand * 1000);
-                    } catch (final InterruptedException e) {
-                        logger.warn("WARN", e);
-                    }
+                @Override
+                public void run() {
+                    ThreadContext.clear();
+
+                    RequestContext.setSessionId("session1234");
+                    RequestContext.setIpAddress("127.0.0.1");
+                    RequestContext.setClientId("02121");
+                    RequestContext.setProductName("IB");
+                    RequestContext.setProductVersion("4.18.1");
+                    RequestContext.setLocale("en_US");
+                    RequestContext.setRegion("prod");
+                    while (generateLog) {
+                        // Generate rand number between 1 to 10
+                        final int rand = ran.nextInt(9) + 1;
+
+                        // Sleep for rand seconds
+                        try {
+                            Thread.sleep(rand * timeBase);
+                        } catch (final InterruptedException e) {
+                            logger.warn("WARN", e);
+                        }
 
-                    // Write rand number of logs
-                    for (int i = 0; i < rand; i++) {
-                        final int eventIndex = (Math.abs(ran.nextInt())) % events.size();
-                        final AuditEvent event = events.get(eventIndex);
-                        RequestContext.setUserId(member);
-                        event.logEvent();
-
-                        if ((rand % 4) == 1) {
-                            logger.debug("DEBUG level logging.....");
-                        } else if ((rand % 4) == 2) {
-                            logger.info("INFO level logging.....");
-                        } else if ((rand % 4) == 3) {
-                            logger.warn("WARN level logging.....");
-                        } else {
-                            logger.error("ERROR level logging.....");
+                        // Write rand number of logs
+                        for (int i = 0; i < rand; i++) {
+                            final int eventIndex = (Math.abs(ran.nextInt())) % events.size();
+                            final AuditEvent event = events.get(eventIndex);
+                            RequestContext.setUserId(member);
+                            event.logEvent();
+
+                            if ((rand % 4) == 1) {
+                                logger.debug("DEBUG level logging.....");
+                            } else if ((rand % 4) == 2) {
+                                logger.info("INFO level logging.....");
+                            } else if ((rand % 4) == 3) {
+                                logger.warn("WARN level logging.....");
+                            } else {
+                                logger.error("ERROR level logging.....");
+                            }
                         }
-                    }
 
+                    }
+                    ThreadContext.cloneStack();
                 }
-                ThreadContext.cloneStack();
-            }
-        }).start();
+            }).start();
+        }
 
         return new ModelAndView("start.jsp");
     }

Modified: logging/log4j/log4j2/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/src/changes/changes.xml?rev=1508572&r1=1508571&r2=1508572&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/src/changes/changes.xml (original)
+++ logging/log4j/log4j2/trunk/src/changes/changes.xml Tue Jul 30 18:20:26 2013
@@ -21,6 +21,9 @@
   </properties>
   <body>
     <release version="2.0-beta9" date="soon, very soon" description="Bug fixes and enhancements">
+      <action issue="LOG4J2-328" dev="rgoers" type="fix">
+        FlumePersistentManager was calling Berkeley DB's count method too frequently.
+      </action>
       <action issue="LOG4J2-325" dev="ggregory" type="update">
         Update JDBC tests to use H2 database 1.3.173 from 1.3.172.
       </action>



Mime
View raw message