On Tue, Feb 14, 2012 at 08:23:10PM -0500, Bruce Momjian wrote:
> On Wed, Feb 15, 2012 at 01:35:05AM +0200, Marko Kreen wrote:
> > On Tue, Feb 14, 2012 at 05:59:06PM -0500, Tom Lane wrote:
> > > Bruce Momjian <[email protected]> writes:
> > > > On Mon, Feb 13, 2012 at 08:28:03PM -0500, Tom Lane wrote:
> > > >> +1, I was about to suggest the same thing. Running any of these tests
> > > >> for a fixed number of iterations will result in drastic degradation of
> > > >> accuracy as soon as the machine's behavior changes noticeably from what
> > > >> you were expecting. Run them for a fixed time period instead. Or
> > > >> maybe
> > > >> do a few, then check elapsed time and estimate a number of iterations
> > > >> to
> > > >> use, if you're worried about the cost of doing gettimeofday after each
> > > >> write.
> > >
> > > > Good idea, and it worked out very well. I changed the -o loops
> > > > parameter to -s seconds which calls alarm() after (default) 2 seconds,
> > > > and then once the operation completes, computes a duration per
> > > > operation.
> > >
> > > I was kind of wondering how portable alarm() is, and the answer
> > > according to the buildfarm is that it isn't.
> >
> > I'm using following simplistic alarm() implementation for win32:
> >
> > https://github.com/markokr/libusual/blob/master/usual/signal.c#L21
> >
> > this works with fake sigaction()/SIGALARM hack below - to remember
> > function to call.
> >
> > Good enough for simple stats printing, and avoids win32-specific
> > code spreading around.
>
> Wow, I wasn't even aware this compiled in Win32; I thought it was
> ifdef'ed out. Anyway, I am looking at SetTimer as a way of making this
> work. (Me wonders if the GoGrid Windows images have compilers.)
>
> I see backend/port/win32/timer.c so I might go with a simple "create a
> thread, sleep(2), set flag, exit" solution.
Yeah, two Windows buildfarm machines have now successfully compiled my
patches, so I guess I fixed it; patch attached.
The fix was surprisingly easy given the use of threads; scheduling the
timeout in the operating system was just too invasive.
I would like to eventually know if this fix actually produces the right
output. How would I test that? Are the buildfarm output binaries
available somewhere? Should I add this as a 9.2 TODO item?
--
Bruce Momjian <[email protected]> http://momjian.us
EnterpriseDB http://enterprisedb.com
+ It's impossible for everything to be true. +
diff --git a/contrib/pg_test_fsync/pg_test_fsync.c b/contrib/pg_test_fsync/pg_test_fsync.c
new file mode 100644
index 02a9e21..7f92bc8
*** a/contrib/pg_test_fsync/pg_test_fsync.c
--- b/contrib/pg_test_fsync/pg_test_fsync.c
***************
*** 28,39 ****
--- 28,54 ----
#define OPS_FORMAT "%9.3f ops/sec"
/* These are macros to avoid timing the function call overhead. */
+ #ifndef WIN32
#define START_TIMER \
do { \
alarm_triggered = false; \
alarm(secs_per_test); \
gettimeofday(&start_t, NULL); \
} while (0)
+ #else
+ /* WIN32 doesn't support alarm, so we create a thread and sleep there */
+ #define START_TIMER \
+ do { \
+ alarm_triggered = false; \
+ if (CreateThread(NULL, 0, process_alarm, NULL, 0, NULL) == \
+ INVALID_HANDLE_VALUE) \
+ { \
+ fprintf(stderr, "Cannot create thread for alarm\n"); \
+ exit(1); \
+ } \
+ gettimeofday(&start_t, NULL); \
+ } while (0)
+ #endif
#define STOP_TIMER \
do { \
*************** static void test_sync(int writes_per_op)
*** 62,68 ****
--- 77,87 ----
static void test_open_syncs(void);
static void test_open_sync(const char *msg, int writes_size);
static void test_file_descriptor_sync(void);
+ #ifndef WIN32
static void process_alarm(int sig);
+ #else
+ static DWORD WINAPI process_alarm(LPVOID param);
+ #endif
static void signal_cleanup(int sig);
#ifdef HAVE_FSYNC_WRITETHROUGH
*************** main(int argc, char *argv[])
*** 82,88 ****
--- 101,109 ----
/* Prevent leaving behind the test file */
signal(SIGINT, signal_cleanup);
signal(SIGTERM, signal_cleanup);
+ #ifndef WIN32
signal(SIGALRM, process_alarm);
+ #endif
#ifdef SIGHUP
/* Not defined on win32 */
signal(SIGHUP, signal_cleanup);
*************** print_elapse(struct timeval start_t, str
*** 550,560 ****
--- 571,592 ----
printf(OPS_FORMAT "\n", per_second);
}
+ #ifndef WIN32
static void
process_alarm(int sig)
{
alarm_triggered = true;
}
+ #else
+ static DWORD WINAPI
+ process_alarm(LPVOID param)
+ {
+ /* WIN32 doesn't support alarm, so we create a thread and sleep here */
+ Sleep(secs_per_test * 1000);
+ alarm_triggered = true;
+ ExitThread(0);
+ }
+ #endif
static void
die(const char *str)
--
Sent via pgsql-hackers mailing list ([email protected])
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers