简体   繁体   中英

C# should I keep open connection in connection pooling

I am working on multi threaded application(a server) where I used to handle 2000 clients at a time and I am opening separate database connection of MySQL database in each thread. So I have enabled the connection pooling. I searched on many blocks that after using connections we should close it then it will return back to pool and will be used by other thread. on the other hand we know that connection making is a time consuming process. So my question is why should we close connection in connection pooling. and what is better keep connection open or close them?

we know that connection making is a time consuming process

Correct - that's why we have connection pools. They maintain connections, so you don't create new ones.

why should we close connection in connection pooling

So they are returned to the pool to be used by other threads.

Connections are expensive resources, so you want to open, use and close them as quickly as possible, so they will return to the pool and be available to other threads.

When you 'Close' a connection that is pooled;You are saying that you are done with the connection and the pool can use it again.

Calling Close does not physically tear down the connection. The pool has its own logic to determine when connections are physically closed.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM