[logback-dev] svn commit: r889 - in logback/trunk: logback-examples/src/main/java/chapter4/db logback-site/src/site/xdocTemplates/manual

noreply.seb at qos.ch noreply.seb at qos.ch
Thu Nov 9 17:19:58 CET 2006


Author: seb
Date: Thu Nov  9 17:19:58 2006
New Revision: 889

Added:
   logback/trunk/logback-examples/src/main/java/chapter4/db/append-toMySQL-with-datasource-and-pooling.xml
   logback/trunk/logback-examples/src/main/java/chapter4/db/append-toMySQL-with-datasource.xml
Modified:
   logback/trunk/logback-site/src/site/xdocTemplates/manual/appenders.xml

Log:
first draft of pooling test results

Added: logback/trunk/logback-examples/src/main/java/chapter4/db/append-toMySQL-with-datasource-and-pooling.xml
==============================================================================
--- (empty file)
+++ logback/trunk/logback-examples/src/main/java/chapter4/db/append-toMySQL-with-datasource-and-pooling.xml	Thu Nov  9 17:19:58 2006
@@ -0,0 +1,28 @@
+<configuration>
+
+	<appender name="DB" class="ch.qos.logback.classic.db.DBAppender">
+		<connectionSource
+			class="ch.qos.logback.core.db.DataSourceConnectionSource">
+			<dataSource
+				class="com.mchange.v2.c3p0.ComboPooledDataSource">
+				<driverClass>com.mysql.jdbc.Driver</driverClass>
+				<jdbcUrl>jdbc:mysql://localhost:3306/logbackdb</jdbcUrl>
+				<user>logback</user>
+				<password>logback</password>
+			</dataSource>
+		</connectionSource>
+	</appender>
+
+	<!-- Prevent internal logback DEBUG messages from polluting the output. -->
+	<logger name="ch.qos.logback.core.joran">
+		<level value="INFO" />
+	</logger>
+	<logger name="ch.qos.logback.classic.joran">
+		<level value="INFO" />
+	</logger>
+
+	<root>
+		<level value="debug" />
+		<appender-ref ref="DB" />
+	</root>
+</configuration>
\ No newline at end of file

Added: logback/trunk/logback-examples/src/main/java/chapter4/db/append-toMySQL-with-datasource.xml
==============================================================================
--- (empty file)
+++ logback/trunk/logback-examples/src/main/java/chapter4/db/append-toMySQL-with-datasource.xml	Thu Nov  9 17:19:58 2006
@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+	  
+<configuration>
+
+	<appender name="DB" class="ch.qos.logback.classic.db.DBAppender">
+		<connectionSource	class="ch.qos.logback.core.db.DataSourceConnectionSource">
+			<dataSource class="com.mysql.jdbc.jdbc2.optional.MysqlDataSource">
+				<serverName>${serverName}</serverName>
+				<port>${port$</port>
+				<databaseName>${dbName}</databaseName>
+				<user>${user}</user>
+				<password>${pass}</password>
+			</dataSource>
+		</connectionSource>
+	</appender>
+
+  <!-- Prevent internal logback DEBUG messages from polluting the output. -->
+  <logger name="ch.qos.logback.core.joran"><level value="INFO" /></logger>
+  <logger name="ch.qos.logback.classic.joran"><level value="INFO" /></logger>
+    
+    
+	<root>
+		<level value="debug" />
+		<appender-ref ref="DB" />
+	</root>
+
+</configuration>
\ No newline at end of file

Modified: logback/trunk/logback-site/src/site/xdocTemplates/manual/appenders.xml
==============================================================================
--- logback/trunk/logback-site/src/site/xdocTemplates/manual/appenders.xml	(original)
+++ logback/trunk/logback-site/src/site/xdocTemplates/manual/appenders.xml	Thu Nov  9 17:19:58 2006
@@ -2096,7 +2096,100 @@
 			<em>jndi.properties</em>
 			file as described by your JNDI provider's documentation.
 		</p>
+		
+		<h4>Connection pooling</h4>
+		
+		<p>
+			Logging events can be created at a rather fast pace. To keep up
+			with the flow of events that must be inserted into a database, 
+			it is recommanded to use connection pooling with
+			<code>DBAppender</code>.
+		</p>
+		
+		<p>
+			Experiment shows that using connection pooling with <code>DBAppender</code>
+			gives a big boost to the process' performance. With the following
+			configuration file, logging events are sent to a MySQL database,
+			without any pooling.
+		</p>
+<em>Example 4.8: <code>DBAppender</code> configuration without pooling (logback-examples/src/main/java/chapter4/db/append-toMySQL-with-datasource.xml)</em>	
+<div class="source"><pre>&lt;configuration>
+
+  &lt;appender name="DB" class="ch.qos.logback.classic.db.DBAppender">
+    &lt;connectionSource class="ch.qos.logback.core.db.DataSourceConnectionSource">
+      &lt;dataSource class="com.mysql.jdbc.jdbc2.optional.MysqlDataSource">
+        &lt;serverName>${serverName}&lt;/serverName>
+        &lt;port>${port$&lt;/port>
+        &lt;databaseName>${dbName}&lt;/databaseName>
+        &lt;user>${user}&lt;/user>
+        &lt;password>${pass}&lt;/password>
+      &lt;/dataSource>
+    &lt;/connectionSource>
+  &lt;/appender>
+
+  &lt;!-- Prevent internal logback DEBUG messages from polluting the output. -->
+  &lt;logger name="ch.qos.logback.core.joran">
+    &lt;level value="INFO" />
+  &lt;/logger>
+  &lt;logger name="ch.qos.logback.classic.joran">
+    &lt;level value="INFO" />
+  &lt;/logger>
+    
+  &lt;root>
+    &lt;level value="debug" />
+    &lt;appender-ref ref="DB" />
+  &lt;/root>
+&lt;/configuration</pre></div>
+
+		<p>
+			With this configuration file, sending 500 logging events to
+			a MySQL database takes a whopping 22 seconds. This figure is absolutely
+			unacceptable when dealing with large applications.
+		</p>
+
+		<p>
+			A dedicated external library is necessary to use connection pooling
+			with <code>DBAppender</code>. The next example uses 
+			<a href="http://sourceforge.net/projects/c3p0">c3p0</a>. To be able
+			to use c3p0, one must download it and place <em>c3p0-VERSION.jar</em>
+			in the classpath.
+		</p>
+
+<em>Example 4.8: <code>DBAppender</code> configuration with pooling (logback-examples/src/main/java/chapter4/db/append-toMySQL-with-datasource-and-pooling.xml)</em>			
+<div class="source"><pre>&lt;configuration>
+
+  &lt;appender name="DB" class="ch.qos.logback.classic.db.DBAppender">
+    &lt;connectionSource
+      class="ch.qos.logback.core.db.DataSourceConnectionSource">
+      <b>&lt;dataSource
+        class="com.mchange.v2.c3p0.ComboPooledDataSource">
+        &lt;driverClass>com.mysql.jdbc.Driver&lt;/driverClass>
+        &lt;jdbcUrl>jdbc:mysql://${serverName}:${port}/${dbName}&lt;/jdbcUrl>
+        &lt;user>${user}&lt;/user>
+        &lt;password>${password}&lt;/password>
+      &lt;/dataSource></b>
+    &lt;/connectionSource>
+  &lt;/appender>
 
+  &lt;!-- Prevent internal logback DEBUG messages from polluting the output. -->
+  &lt;logger name="ch.qos.logback.core.joran">
+    &lt;level value="INFO" />
+  &lt;/logger>
+  &lt;logger name="ch.qos.logback.classic.joran">
+    &lt;level value="INFO" />
+  &lt;/logger>
+
+  &lt;root>
+    &lt;level value="debug" />
+    &lt;appender-ref ref="DB" />
+  &lt;/root>
+&lt;/configuration></pre></div>
+
+		<p>
+			With this new configuration, sending 500 logging requests to
+			the same MySQL database as previously used takes no more than 5 seconds.
+			The gain is a <em>4.4</em> factor. 
+		</p>
 
 		<h3>SyslogAppender</h3>
 		



More information about the logback-dev mailing list