I have read that making connections is very expensive, and I have read that keeping connections open is very expensive.
I have a windows client/server App. There will typically be 3-5 client users accessing the system at any given time, all on a local area network. When they are using the system, they might use it for an hour or more. While viewing the data, they will m
ake frequent requests from the database. (In some cases, the screens they are viewing will automatically refresh, by sending a new query to the database.) In other words, each client might request new data every 5 seconds or so.
Also, there is a service running that automatically monitors machines, and puts the recorded data into a database, resulting in a database updata once per second from each machine. There are anywhere from 4 to 100 machines.
My question is whether I would be better off to create a database connection at the time the user logs on, and maintain that connection until he logs off, or would it be better to create and use a new connection for every query. Using a new connection fo
r every query, I get the overhead associated with new connections. Keeping the connection alive the whole time, I get the overhead associated with maintaining a connection.
Likewise, with the machine monitoring connections, would I be better off opening a connection for each machine, and keeping it alive as long as the monitoring continued, or would I be better off creating and disposing of it frequently?
In case it matters, this is all using Visual C# with ADO.net.
Generally, most apps are written today to close the connections when you're
done with them. Web applications especially open and close connections
very frequently. The client will use connection pooling to reduce the
overhead of establishing brand new connections so the perf hit isn't so bad.
Most performace gains are achieved by tuning the queries you're sending to
the server etc. and good database design.
Thanks,
Kevin McDonnell
Microsoft Corporation
This posting is provided AS IS with no warranties, and confers no rights.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment