Search Postgresql Archives

Re: Asynchronous queries with bound data.

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

 



1: Didn't figured out what it does mean - can you explain it better?

2: Operation system will refuse me to create thousand threads and, anyway, database will return responds averagely just when all of them will be accomplished.

3: I never close a connection once it was created, so any pool will not help me (I google says right about "connection pool").

I found the _expression_: "you can't issue another PQsendQuery until you've gotten that NULL." - so if it is true, then it's impossible (because it's only one function available to send an asynchronous request) to send multiple requests before any result will be gotten.

Problem can be observed from this abstract point of view:
Transferring data from application server (which connects to the database) takes 200 ms (and the same amount to transfer backward); adding data to the database and then selecting data (all in one request) from it takes 250 ms, so each database operation (of such type) will take 200 + 250 + 200 = 650 ms. Two such operations will take 650 + 650 = 1300 ms, but if there existed the way to send two queries at once and then get two results at once (of course tracking the correspondence between requests/responds) we could decrease such two "dialogs" from 1300 ms to 200 + 250 + 250 + 200 = 900 ms. So, we win 400 ms - when there are thousand requests per several minutes - it bocomes to be a very good time.

6 января 2011 г. 1:07 пользователь Peter Geoghegan <peter.geoghegan86@xxxxxxxxx> написал:
2011/1/5 Вячеслав Блинников <slavmfm@xxxxxxxxx>:
> The whole thing is:
> - server connect to the database and wait for incoming connections
> - when incoming connection occurs, server request the database for some data
> about connected client - server must do it asynchronously and without
> creating any threads just for connected client (there can be more than
> thousand clients)
> - at moment of requesting data from the database there already can be some
> active requests
> - when database respond it is need to know for which client this data
> received (and what kind of request it was)
> That's all.
>
> P.S. it is possible to implement it requesting data one-by-one (adding each
> request to the queue and popping (FIFO) each request after each database'
> respond) but it is slow because it's need to wait data transferring through
> the net while database (server) itself will be idling.

I'm afraid I don't understand your problem, but may I suggest that you:

1. Wrap the connection in a semaphore. This isn't pretty, but if I've
understood you correctly, it will do the job.

or

2. Have one database connection per "server" client. Having one
process that itself has up to a thousand clients but uses only one PG
connection is a very questionable approach - the single database
connection is certain to become a bottleneck.

and

3. Use a connection pooler.

--
Regards,
Peter Geoghegan


[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