logback dbappender 性能

发布于 2024-12-09 04:14:28 字数 2585 浏览 0 评论 0原文

我希望在应用程序中使用 Logback Classic DB Appender (ch.qos.logback.classic.db.DBAppender)。数据库是Sybase ASE。我使用c3p0连接池。

除了数据库附加器之外,我还有一个滚动文件附加器。问题是,使用 DB Appender 我发现性能急剧下降。例如,如果仅使用滚动文件附加程序,则需要 13 毫秒(毫秒)才能将消息记录到文件中。但是,如果同时滚动文件追加器和数据库追加器,则需要 4510 毫秒(4.5 秒)才能将同一组消息输出到文件和数据库。

Logback DBAppender 文档提到,使用 c3p0 连接池,插入单个日志语句大约需要 1ms。我看到的数字比这个多数千倍。想知道可能出了什么问题。以下是我的 logback.xml 文件:

<configuration debug="true" scan="true">

    <property resource="log.properties" />

    <appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
        <!-- encoders are assigned the type ch.qos.logback.classic.encoder.PatternLayoutEncoder by default -->
        <encoder>
            <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
        </encoder>
    </appender>

    <appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <file>${log.file.dir}/${project.artifactId}.log</file>
        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            <!-- daily rollover -->
            <fileNamePattern>${project.artifactId}.%d{yyyy-MM-dd}.log</fileNamePattern>
            <!-- keep 30 days' worth of history -->
            <maxHistory>${log.file.rolling.history.days}</maxHistory>
        </rollingPolicy>

        <encoder>
            <pattern>%-4relative [%thread] %-5level %logger{35} - %msg%n</pattern>
        </encoder>
    </appender>

    <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>${log.db.driver}</driverClass>
                <jdbcUrl>jdbc:sybase:Tds:${log.db.server}:${log.db.port}/${log.db.name}</jdbcUrl>
                <serverName>${log.db.server}</serverName>
                <databaseName>${log.db.name}</databaseName>
                <user>${log.db.user}</user>
                <password>${log.db.password}</password>
            </dataSource>
        </connectionSource>
    </appender>

    <root level="INFO">
        <appender-ref ref="CONSOLE" />
        <appender-ref ref="FILE" />
    </root>

</configuration>

任何指针表示赞赏。

谢谢。

I am looking to use Logback Classic DB Appender (ch.qos.logback.classic.db.DBAppender) in the application. Database is Sybase ASE. I use c3p0 connection pool.

Besides the DB appender, I also have a rolling file appender. Problem is, with the DB Appender I see a drastic decrease in performance. For instance, with only rolling file appender, it takes 13 ms (milli seconds) to log the messages to file. However, with rolling file appender and db appender together, it takes 4510 ms (4.5 seconds) to output the same set of messages to file and database.

Logback DBAppender document mentions that with c3p0 connection pool, it takes around 1ms to insert a single logging statement. Numbers I am seeing are thousand times more than that. Wonder what could be wrong. Following is my logback.xml file:

<configuration debug="true" scan="true">

    <property resource="log.properties" />

    <appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
        <!-- encoders are assigned the type ch.qos.logback.classic.encoder.PatternLayoutEncoder by default -->
        <encoder>
            <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
        </encoder>
    </appender>

    <appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <file>${log.file.dir}/${project.artifactId}.log</file>
        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            <!-- daily rollover -->
            <fileNamePattern>${project.artifactId}.%d{yyyy-MM-dd}.log</fileNamePattern>
            <!-- keep 30 days' worth of history -->
            <maxHistory>${log.file.rolling.history.days}</maxHistory>
        </rollingPolicy>

        <encoder>
            <pattern>%-4relative [%thread] %-5level %logger{35} - %msg%n</pattern>
        </encoder>
    </appender>

    <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>${log.db.driver}</driverClass>
                <jdbcUrl>jdbc:sybase:Tds:${log.db.server}:${log.db.port}/${log.db.name}</jdbcUrl>
                <serverName>${log.db.server}</serverName>
                <databaseName>${log.db.name}</databaseName>
                <user>${log.db.user}</user>
                <password>${log.db.password}</password>
            </dataSource>
        </connectionSource>
    </appender>

    <root level="INFO">
        <appender-ref ref="CONSOLE" />
        <appender-ref ref="FILE" />
    </root>

</configuration>

Any pointers appreciated.

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

明媚如初 2024-12-16 04:14:28

我从 logback 手册中发现以下内容:

如果您的 JDBC 驱动程序支持 JDBC 3.0 规范中引入的 getGenerateKeys 方法,假设您已经如上所述创建了相应的数据库表,那么除了通常的 logback 配置之外,不需要更多步骤。

否则,必须有适合您的数据库系统的 SQLDialect。目前,我们有 PostgreSQL、MySQL、Oracle 和 MS SQL Server 的方言。

对于oracle,它说支持的版本是:(10.2.0.1)

链接:
http://logback.qos.ch/manual/appenders.html#DBAppender

如果你的 JDBC 驱动程序中没有 Dialect 类,你可以从 hibernate 获取,并将其放入你的源代码中,我不知道它是否可以工作。

I found the following from logback manual:

If your JDBC driver supports the getGeneratedKeys method introduced in JDBC 3.0 specification, assuming you have created the appropriate database tables as mentioned above, then no more steps are required, except for the usual logback configuration.

Otherwise, there must be an SQLDialect appropriate for your database system. Currently, we have dialects for PostgreSQL, MySQL, Oracle and MS SQL Server.

for oracle, it said the supported version is :(10.2.0.1)

link:
http://logback.qos.ch/manual/appenders.html#DBAppender

If you have no a Dialect class in your JDBC driver, you can get from hibernate, and put it in your source, I don't know whether it can work.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文