Search Postgresql Archives

Re: Should PQconsumeInput/PQisBusy be expensive to use?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, Oct 27, 2010 at 15:02, Michael Clark <codingninja@xxxxxxxxx> 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...

-- 
Sent via pgsql-general mailing list (pgsql-general@xxxxxxxxxxxxxx)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general



[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux