[libvirt-users] connection creating

Daniel P. Berrange berrange at redhat.com
Wed Mar 31 17:45:08 UTC 2010


On Wed, Mar 31, 2010 at 10:30:58AM -0700, jeremy avnet wrote:
> Are there any recommendations as to how often a new connection should be
> made versus reused? Right now we create a new connection *every time* we hit
> libvirt for something. We can easily change this so that a single connection
> is made for a series of libvirt calls, or even so that a single connection
> is used for the lifetime of the running application.
> 
> What are the issues to consider when making these choices?

As of libvirt 0.7.0 or later, libvirt is fully threadsafe allowing many
threads to use the same virConnectPtr concurrently. It will do all
neccessary locking internally to ensure safety. When no API calls are being
issued, there is no harm in keeping the libvirt connection open.

Using a single connection, open at all times you avoid the potentially
high overhead of authentication & encryption setup  at time of connect.

I'd always recommend using a single, permanently open connection these days.

Oh, and if you keep the connection open you can register for async events
to be notified when interesting things happen in QEMU

Regards,
Daniel
-- 
|: Red Hat, Engineering, London    -o-   http://people.redhat.com/berrange/ :|
|: http://libvirt.org -o- http://virt-manager.org -o- http://deltacloud.org :|
|: http://autobuild.org        -o-         http://search.cpan.org/~danberr/ :|
|: GnuPG: 7D3B9505  -o-   F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|




More information about the libvirt-users mailing list