Re: Should PQconsumeInput/PQisBusy be expensive to use?
От | Alex Hunsaker |
---|---|
Тема | Re: Should PQconsumeInput/PQisBusy be expensive to use? |
Дата | |
Msg-id | AANLkTinZSBk4e22d4u750N2br9sCcSQWcVu5tFnHXh++@mail.gmail.com обсуждение исходный текст |
Ответ на | Should PQconsumeInput/PQisBusy be expensive to use? (Michael Clark <codingninja@gmail.com>) |
Список | pgsql-general |
On Wed, Oct 27, 2010 at 15:02, Michael Clark <codingninja@gmail.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...
В списке pgsql-general по дате отправления: