Multiple, concurrent connection requests take a (very) long time to initialize

53 views
Skip to first unread message

siki

unread,
Nov 12, 2014, 5:50:01 PM11/12/14
to npgsq...@googlegroups.com
Hi,

I must state at the beginning that I'm fairly new to .Net. This is not my primary development language. I'm using F# for a smaller project to write an add-in for Excel. This plugin connects to a PostgreSQL database to fetch data via user defined functions. These UDFs return their results asynchronously and can be run concurrently, i.e. you can have many (100's) of UDF run at the same time.

My connection is set up like this:

type internal conn =
   
SqlEntityConnection<ConnectionString= @"Server=database; Database=foo; User=reader; Password=reading; ApplicationName=ExcelAddIn; Preload Reader=true; MinPoolSize=20; CommandTimeout=600;",
                       
LocalSchemaFile = "FooSchema.ssdl",
                       
ForceUpdate = false,
                       
Provider="Npgsql">


Now, the functions that actually fetch the data from the DB get a connection from the pool by having: 

use db = conn.GetDataContext()  

and then execute their queries. 

I noticed that all is good if I only have a couple of dozen UDFs executing at the same time but once I get to say 50-100, nothing happens for a few minutes. It looks to me that the pool is not even set up for these few minutes (I'm looking at the database server side for connections). I also noticed that if the pool is "set up" first by executing a single UDF and therefore a single request to conn.GetDataContext(), and then the other 100 UDF are executed at the same time, it works fine. I can replicate this behavior repeatedly, and the only solution I could come up with to work around this was to execute a dummy query first in the AutoOpen section of the code, which "causes" the pool to be set up.

Why is this happening and what's a better solution? All help is appreciated!

siki

unread,
Apr 29, 2015, 11:08:49 AM4/29/15
to npgsq...@googlegroups.com
Just bumping this up. Does anyone have any input/suggestion on this? Thanks in advance! 
Reply all
Reply to author
Forward
0 new messages