Skip to main content

Posts

Showing posts from April, 2010

Npgsql Connection Pool Explained

Hi all! From time to time, we receive some questions regarding connection pool in Npgsql and I think I should post some info about its current design. Npgsql connection pool implements the common pattern of having some connections open beforehand so when one is needed, it will be readily available for using. How it works When a application opens a connection, Npgsql tries to find a pool of connections based on the connection string. If a pool doesn't exist, it is created with a number of connections specified in the MinPoolSize connectionstring parameter. After that, a connection is retrieved from this pool. The min and max number of connections created in each pool is controlled by connection string parameters called MinPoolSize and MaxPoolSize respectively. This way, users can fine tune the pool behavior to match their scalability needs. Npgsql controls the lifetime of unused connections in the pool, trying to get connections number near the minimum value set by user. This is d

Function call performance optimizations

On my last post about that subject , I wrote about some optimizations I did to get better performance when calling functions with Npgsql. While that optimizations were very nice, they had a drawback: you had to reuse your NpgsqlCommand object. You had to reuse it because the optimizations were based on cached data and if you created a new NpgsqlCommand object the data would need to be cached again. In the general case, where you would create many NpgsqlCommand objects and call functions with them, you would not benefit from those optimizations. In order to fix that, Noah Misch created a patch which remove 2 of the 3 internal calls which were giving performance problems. The only case left is for functions which have return type of 'record'. We are working to get this case also covered. I'm going to show here how much performance improvement you get with this patch with a simple call to a function which returns an integer. This function is on Npgsql unit test suite, but I

Using SSL Client Certificates with Npgsql

Hi all! Recently, Jarrod Kinsley asked on our Forums how to establish an SSL connection . As Laurenz Albe pointed out, normally you just need to change your connection string to put "SSL=True;Sslmode=Require;" in your connection string and "ssl=on" in postgresql.conf and you are ready to go. The problem was that this works in the general case where you don't have to deal with client certificates and other stuff. Npgsql has a lot of callbacks to help you to validate and talk to the server. The last callback added to the chain by Frank Bollack was to provide a way to pass client certificates to server. Later on the thread, Jennifer Marienfeld was also trying to connect and was stuck in the client certificate part. Jennifer eventually got success to establish connection to the server and I decided to create this post to show the code so others can benefit from this. Here is Jennifer's code so you all can use as a template: using System; using System.IO; us