Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit3793310

Browse files
committed
Fix performance bug in write_syslog(): the code to preferentially break the
log message at newlines cost O(N^2) for very long messages with few or nonewlines. For messages in the megabyte range this became the dominant cost.Per gripe from Achilleas Mantzios.Patch all the way back, since this is a safe change with no portabilityrisks. I am also thinking of increasing PG_SYSLOG_LIMIT, but that shouldbe done separately.
1 parentcac2f69 commit3793310

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

‎src/backend/utils/error/elog.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
*
4343
*
4444
* IDENTIFICATION
45-
* $PostgreSQL: pgsql/src/backend/utils/error/elog.c,v 1.203 2008/03/24 18:08:47 tgl Exp $
45+
* $PostgreSQL: pgsql/src/backend/utils/error/elog.c,v 1.204 2008/07/08 22:17:41 tgl Exp $
4646
*
4747
*-------------------------------------------------------------------------
4848
*/
@@ -1306,6 +1306,7 @@ write_syslog(int level, const char *line)
13061306
staticunsigned longseq=0;
13071307

13081308
intlen;
1309+
constchar*nlpos;
13091310

13101311
/* Open syslog connection if not done yet */
13111312
if (!openlog_done)
@@ -1328,17 +1329,17 @@ write_syslog(int level, const char *line)
13281329
* fact, it does work around by splitting up messages into smaller pieces.
13291330
*
13301331
* We divide into multiple syslog() calls if message is too long or if the
1331-
* message contains embeddedNewLine(s) '\n'.
1332+
* message contains embeddednewline(s).
13321333
*/
13331334
len=strlen(line);
1334-
if (len>PG_SYSLOG_LIMIT||strchr(line,'\n')!=NULL)
1335+
nlpos=strchr(line,'\n');
1336+
if (len>PG_SYSLOG_LIMIT||nlpos!=NULL)
13351337
{
13361338
intchunk_nr=0;
13371339

13381340
while (len>0)
13391341
{
13401342
charbuf[PG_SYSLOG_LIMIT+1];
1341-
constchar*nlpos;
13421343
intbuflen;
13431344
inti;
13441345

@@ -1347,11 +1348,12 @@ write_syslog(int level, const char *line)
13471348
{
13481349
line++;
13491350
len--;
1351+
/* we need to recompute the next newline's position, too */
1352+
nlpos=strchr(line,'\n');
13501353
continue;
13511354
}
13521355

13531356
/* copy one line, or as much as will fit, to buf */
1354-
nlpos=strchr(line,'\n');
13551357
if (nlpos!=NULL)
13561358
buflen=nlpos-line;
13571359
else

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp