pgbench on mingw needs fflush

Started by ITAGAKI Takahiroover 19 years ago7 messagespatches
Jump to latest
#1ITAGAKI Takahiro
itagaki.takahiro@oss.ntt.co.jp

pgbench reports its progress of loading ("N tuples done.") or vacuuming
("vacuum...end"), but the messages are not printed on the moment on mingw.
The reason seems to be the buffering of stderr. This patch adds fflush()
just after each fprintf(stderr).

The buffered stderr might be a bug of mingw, but redundant fflush()
does not make mischief for platforms that have correct stderr.

Regards,
---
ITAGAKI Takahiro
NTT Open Source Software Center

Attachments:

pgbench.fflush.diffapplication/octet-stream; name=pgbench.fflush.diffDownload+9-0
#2Tatsuo Ishii
ishii@postgresql.org
In reply to: ITAGAKI Takahiro (#1)
Re: pgbench on mingw needs fflush

Can we distinguish mingw case from others so that we could ifdef out
the extra fflush()?
--
Tatsuo Ishii
SRA OSS, Inc. Japan

Show quoted text

pgbench reports its progress of loading ("N tuples done.") or vacuuming
("vacuum...end"), but the messages are not printed on the moment on mingw.
The reason seems to be the buffering of stderr. This patch adds fflush()
just after each fprintf(stderr).

The buffered stderr might be a bug of mingw, but redundant fflush()
does not make mischief for platforms that have correct stderr.

Regards,
---
ITAGAKI Takahiro
NTT Open Source Software Center

#3Tatsuo Ishii
ishii@postgresql.org
In reply to: ITAGAKI Takahiro (#1)
Re: pgbench on mingw needs fflush

Can we distinguish mingw case from others so that we could ifdef out
the extra fflush()?
--
Tatsuo Ishii
SRA OSS, Inc. Japan

Show quoted text

pgbench reports its progress of loading ("N tuples done.") or vacuuming
("vacuum...end"), but the messages are not printed on the moment on mingw.
The reason seems to be the buffering of stderr. This patch adds fflush()
just after each fprintf(stderr).

The buffered stderr might be a bug of mingw, but redundant fflush()
does not make mischief for platforms that have correct stderr.

Regards,
---
ITAGAKI Takahiro
NTT Open Source Software Center

#4Tom Lane
tgl@sss.pgh.pa.us
In reply to: Tatsuo Ishii (#2)
Re: pgbench on mingw needs fflush

Tatsuo Ishii <ishii@sraoss.co.jp> writes:

Can we distinguish mingw case from others so that we could ifdef out
the extra fflush()?

Isn't the right fix a single-spot patch to force stderr into unbuffered
mode? It's supposed to be that way already per spec. I could see a
one-or-two-line patch to remind mingw of the buffer mode it's supposed
to be using ... I'm not excited about making an ongoing commitment to
remember to fflush() after every write call, especially not when no
standard-compliant platform needs it.

regards, tom lane

#5ITAGAKI Takahiro
itagaki.takahiro@oss.ntt.co.jp
In reply to: Tatsuo Ishii (#2)
Re: pgbench on mingw needs fflush

Tatsuo Ishii <ishii@sraoss.co.jp> wrote:

Can we distinguish mingw case from others so that we could ifdef out
the extra fflush()?

The buffered stderr might be a bug of mingw

After a little research, I found that MSDN says the buffered stderr is
a specifications on Windows somehow, not a bug.

setvbuf() is better solution for the problem.
This is more simple and no need to use ifdef.

*** pgbench.c.orig	Mon Jan 22 11:17:30 2007
--- pgbench.c	Tue Mar 13 17:01:12 2007
*************** main(int argc, char **argv)
*** 1184,1189 ****
--- 1184,1192 ----

char val[64];

+ 	/* stderr is buffered on Win32. */
+ 	setvbuf(stderr, NULL, _IONBF, 0);
+ 
  	if ((env = getenv("PGHOST")) != NULL && *env != '\0')
  		pghost = env;
  	if ((env = getenv("PGPORT")) != NULL && *env != '\0')

Regards,
---
ITAGAKI Takahiro
NTT Open Source Software Center

#6Magnus Hagander
magnus@hagander.net
In reply to: ITAGAKI Takahiro (#5)
Re: pgbench on mingw needs fflush

On Tue, Mar 13, 2007 at 05:09:15PM +0900, ITAGAKI Takahiro wrote:

Tatsuo Ishii <ishii@sraoss.co.jp> wrote:

Can we distinguish mingw case from others so that we could ifdef out
the extra fflush()?

The buffered stderr might be a bug of mingw

After a little research, I found that MSDN says the buffered stderr is
a specifications on Windows somehow, not a bug.

setvbuf() is better solution for the problem.
This is more simple and no need to use ifdef.

I was just going to suggest this, because this is what we already use in
the backend (src/backend/main/main.c).

Applied, but with the #ifdefs, because that's cleaner and that's also
how we do it in the backend.

//Magnus

#7Bruce Momjian
bruce@momjian.us
In reply to: Magnus Hagander (#6)
Re: pgbench on mingw needs fflush

Magnus Hagander wrote:

On Tue, Mar 13, 2007 at 05:09:15PM +0900, ITAGAKI Takahiro wrote:

Tatsuo Ishii <ishii@sraoss.co.jp> wrote:

Can we distinguish mingw case from others so that we could ifdef out
the extra fflush()?

The buffered stderr might be a bug of mingw

After a little research, I found that MSDN says the buffered stderr is
a specifications on Windows somehow, not a bug.

setvbuf() is better solution for the problem.
This is more simple and no need to use ifdef.

I was just going to suggest this, because this is what we already use in
the backend (src/backend/main/main.c).

Applied, but with the #ifdefs, because that's cleaner and that's also
how we do it in the backend.

And the #ifdef documents we need it only on Win32. Without it, someone
might remove it thinking Unix doesn't need it.

--
Bruce Momjian <bruce@momjian.us> http://momjian.us
EnterpriseDB http://www.enterprisedb.com

+ If your life is a hard drive, Christ can be your backup. +