Re: Should PQconsumeInput/PQisBusy be expensive to use?

From: Alex Hunsaker <badalex(at)gmail(dot)com>
To: Michael Clark <codingninja(at)gmail(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Should PQconsumeInput/PQisBusy be expensive to use?
Date: 2010-10-27 21:30:43
Message-ID: AANLkTinZSBk4e22d4u750N2br9sCcSQWcVu5tFnHXh++@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Wed, Oct 27, 2010 at 15:02, Michael Clark <codingninja(at)gmail(dot)com> wrote:
> Hello everyone.
> Upon some investigation I found that not calling PQconsumeInput/PQisBusy
> produces results in line with PQexecParams (which PQexecParams seems to be
> doing under the hood).

> (please keep in mind this is just test code and rather simplistic...)
>     int send_result = PQsendQueryParams(self.db,
>                                         [sql UTF8String],
>                                         i,
>                                         NULL,
>                                         (const char *const *)vals,
>                                         (const int *)lens,
>                                         (const int *)formats,
>                                         kTextResultFormat);
>     int consume_result = 0;
>     int is_busy_result = 0;
>
>     while ( ((consume_result = PQconsumeInput(self.db)) == 1) &&
> ((is_busy_result = PQisBusy(self.db)) == 1) )
>         ;

You really want to select() or equivalent here... This basically is a
busy loop using 100% cpu; neither PQconsumeInput or PQisBusy do any
kind of sleeping...

Something like:
fd_set read_mask;
int sock = PQsocket(st->con);
FD_ZERO(&read_mask);
FD_SET(sock, &read_mask);

while(1)
{
struct timeval tv = {5, 0};
select(sock+1, &read_mask, NULL, NULL, &tv);
PQconsumeInput(self.db)
if(!PQisBusy(self.db))
break;
}

or something...

In response to

Browse pgsql-general by date

  From Date Subject
Next Message David Wilson 2010-10-27 21:31:59 Re: Should PQconsumeInput/PQisBusy be expensive to use?
Previous Message Daniel.Crespo 2010-10-27 21:19:20 Re: How to merge data from two separate databases into one (maybe using xlogs)?