OCCI connectionpool doesn't work well

转载自: p://www.orafaq.com/forum/t/51944/0/
 
问:a multi-thread program I create a connectionpool, setting the maxconn as 1. All threads will create a pooled connection. But when the program is running, I logged in the database connected and selected the v$session table. I found the sessions number is not one. I am confuesd. I think the pooled connections are not the real connections to the database. If the maxconn is 1, the session number should be 1. Is it right? Does the connectionpool work or not?
 
答: The ConnectionPool pools the physical connections. If the pool max is 5, there will be a maximum of 5 real physical connections with 5 primary(internal) sessions created. Now if the pool is used by 100 threads with 100 user sessions, you will see a total of 100+5 sessions. Do not bother about the 5 sessions, they are used for internal purposes.

If you are using StatelessConnectionPool, it pools the physical connections+sessions. That means if the pool max is 5, there will be a maximum of 5 real physical connections and 5 user sessions. The threads will have to get/put connections from/into this pool.
 
问: Do the connection pool improve the performace?

The StatelessConnectionPool can work, but its performance is bad. The program can do 300 operations per second when using connectionpool. But when using stateless the program can only do about 30 operations per second. If I connected the database without any connection pool, the program can handle almost 1000 operations per second.

How can I improve the performance in a multi-thread program?
 
答: What is your concurrency? When you don't use any pools and achieve 1000 operations per second, you may be having every thread having its own connection. What is the maximum number of threads? If you configure the pool max to be same as the max number of threads, you will achieve the same speed. The idea of pooling resources is to optimally use them. Please configure the pool max to the maximum concurrency of your database operations.i.e, how many threads do you want to be doing database operations at the same time.
For connection pools, you have a session for every thread, but you pick a physical connection from the pool. For Stateless connection pools, you pick the session+connection from the pool. It should be used for short spanning database operations (like one execute+fetch) and not for long running transactions.
Tune the pool's min/max parameters for achieving better concurrency.

你可能感兴趣的:(职场,connectionpool,休闲,occi)