Kouhei Sutou
null+****@clear*****
Tue May 21 14:23:25 JST 2013
Kouhei Sutou 2013-05-21 14:23:25 +0900 (Tue, 21 May 2013) New Revision: b354f1647f604221035112d46e79701cc1d43984 https://github.com/groonga/groonga/commit/b354f1647f604221035112d46e79701cc1d43984 Message: Don't log the same messages It avoids too many needless log messages. Too many log messages cause too much disk I/O. It is a serious performance issue. Modified files: lib/ctx.c lib/ctx.h lib/ctx_impl.h Modified: lib/ctx.c (+35 -0) =================================================================== --- lib/ctx.c 2013-05-20 19:00:59 +0900 (559964d) +++ lib/ctx.c 2013-05-21 14:23:25 +0900 (4bbfe3f) @@ -505,6 +505,9 @@ grn_ctx_impl_init(grn_ctx *ctx) grn_loader_init(&ctx->impl->loader); ctx->impl->plugin_path = NULL; + ctx->impl->previous_errbuf[0] = '\0'; + ctx->impl->n_same_error_messages = 0; + #ifdef GRN_WITH_MESSAGE_PACK msgpack_packer_init(&ctx->impl->msgpacker, ctx, grn_msgpack_buffer_write); #endif @@ -527,6 +530,37 @@ grn_ctx_impl_err(grn_ctx *ctx) } } +static void +grn_ctx_impl_clear_n_same_error_mssagges(grn_ctx *ctx) +{ + if (ctx->impl->n_same_error_messages == 0) { + return; + } + + GRN_LOG(ctx, GRN_LOG_NOTICE, "(%u same messages are truncated)", + ctx->impl->n_same_error_messages); + ctx->impl->n_same_error_messages = 0; +} + +grn_bool +grn_ctx_impl_should_log(grn_ctx *ctx) +{ + if (!ctx->impl) { + return GRN_TRUE; + } + + if (strcmp(ctx->errbuf, ctx->impl->previous_errbuf) == 0) { + ctx->impl->n_same_error_messages++; + return GRN_FALSE; + } + + grn_ctx_impl_clear_n_same_error_mssagges(ctx); + + strcpy(ctx->impl->previous_errbuf, ctx->errbuf); + + return GRN_TRUE; +} + grn_rc grn_ctx_init(grn_ctx *ctx, int flags) { @@ -592,6 +626,7 @@ grn_ctx_fin(grn_ctx *ctx) CRITICAL_SECTION_LEAVE(grn_glock); } if (ctx->impl) { + grn_ctx_impl_clear_n_same_error_mssagges(ctx); if (ctx->impl->finalizer) { ctx->impl->finalizer(ctx, 0, NULL, &(ctx->user_data)); } Modified: lib/ctx.h (+6 -3) =================================================================== --- lib/ctx.h 2013-05-20 19:00:59 +0900 (e28040a) +++ lib/ctx.h 2013-05-21 14:23:25 +0900 (20511ee) @@ -96,6 +96,7 @@ extern "C" { #endif /* HAVE_BACKTRACE */ GRN_API void grn_ctx_impl_err(grn_ctx *ctx); +GRN_API grn_bool grn_ctx_impl_should_log(grn_ctx *ctx); #ifdef HAVE_BACKTRACE #define LOGTRACE(ctx,lvl) do {\ @@ -121,9 +122,11 @@ GRN_API void grn_ctx_impl_err(grn_ctx *ctx); ctx_->errfunc = __FUNCTION__;\ grn_ctx_impl_err(ctx);\ grn_ctx_log(ctx, __VA_ARGS__);\ - GRN_LOG(ctx, lvl, __VA_ARGS__);\ - BACKTRACE(ctx);\ - if (lvl <= GRN_LOG_ERROR) { LOGTRACE(ctx, lvl); }\ + if (grn_ctx_impl_should_log(ctx)) {\ + GRN_LOG(ctx, lvl, __VA_ARGS__);\ + BACKTRACE(ctx);\ + if (lvl <= GRN_LOG_ERROR) { LOGTRACE(ctx, lvl); }\ + }\ } while (0) #define ERRP(ctx,lvl) \ Modified: lib/ctx_impl.h (+3 -0) =================================================================== --- lib/ctx_impl.h 2013-05-20 19:00:59 +0900 (56454d2) +++ lib/ctx_impl.h 2013-05-21 14:23:25 +0900 (8a1d41f) @@ -169,6 +169,9 @@ struct _grn_ctx_impl { uint64_t u64; } data; + char previous_errbuf[GRN_CTX_MSGSIZE]; + unsigned int n_same_error_messages; + #ifdef GRN_WITH_MESSAGE_PACK msgpack_packer msgpacker; #endif -------------- next part -------------- HTML����������������������������... ダウンロード