On Fri, January 6, 2006 20:26, Luis Silva wrote:
> I think pipeline may be a good solution. How can I use it? tks again and
> sorry for the inconvenience.

You should have reference documentation (doc/html/Reference/index.html)
that describes this class.

It's really pretty easy: you submit queries for execution using the
insert() member function, and retrieve results using the retrieve()
functions.  The latter support two modes of operation--either retrieve
everything in the same sequence you submitted them in, or in more complex
programs, by an identifier that the insert() function returned.  In either
case, the queries will be executed in the same order in which they were
inserted.

The advantage over regular, synchronous query execution is that you don't
have to sit and wait until you get your result.  You can do other useful
work in the meantime, until you get to the point where you really need
that result.  That's where the pipeline may have to sit and wait for a bit
more, but the difference is hidden from your program.

The advantage over conventional nonblocking/asynchronous query execution
is that you're not limited to a single in-flight query.  You can just
stack 'em up on one end, and retrieve results as you need them on the
other.  Generally it's best to put as much useful work as possible between
the moment you issue a query to the pipeline and the moment you extract
the result.  If you're talking to the server over a network, the queries
will be bundled up into fewer packets, and the server also gets a chance
to do useful work while otherwise it might be sitting idle waiting for the
next query.

The catch is that the pipeline doesn't intrinsically know when is a good
moment to send the pending queries to the server.  This is a choice it has
to make continuously.  Of course it has to send the queries when you start
requesting their results, but on the other hand it shouldn't delay issuing
a query until the very last moment either.

Even though all this is completely transparent functionally, you do get to
influence the policy.  This is done through the retain() function, which
lets you set how many queries the pipeline should retain before bundling
them up and sending them to the server.  You can change this at any time,
and you may want to play with it to see what gives you best results for
your particular scenario.


Jeroen


_______________________________________________
Libpqxx-general mailing list
[email protected]
http://gborg.postgresql.org/mailman/listinfo/libpqxx-general

Reply via email to