[ 
https://issues.apache.org/jira/browse/CAY-1864?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13818732#comment-13818732
 ] 

Andrus Adamchik commented on CAY-1864:
--------------------------------------

It's been a while since I used Cayenne built-in pool for connection pooling. 
While it is entirely safe to use in production, it is intentionally simple and 
doesn't have many of the bells and whistles of the alternatives, e.g. [1] - the 
one that I am using now. 

Having said that, I have no objections to improving the algorithm, such as 
adding fair ordering, if it doesn't add much overhead of its own. 

Question on the use of Deque - in our case we seem to just need a queue, not a 
deque?

Also I feel that we may get a bigger bang for the buck if we drop traditional 
Java synchronization approach and start using concurrent utils. E.g. Semaphore 
[2] already supports fair ordering of threads.

[1] http://tomcat.apache.org/tomcat-7.0-doc/jdbc-pool.html
[2] http://docs.oracle.com/javase/7/docs/api/java/util/concurrent/Semaphore.html

> Process threads waiting for an available DB connection in the order they came 
> in
> --------------------------------------------------------------------------------
>
>                 Key: CAY-1864
>                 URL: https://issues.apache.org/jira/browse/CAY-1864
>             Project: Cayenne
>          Issue Type: Improvement
>          Components: Core Library
>    Affects Versions: 3.2M1
>            Reporter: John Huss
>            Assignee: John Huss
>         Attachments: 
> 0001-CAY-1864-Process-threads-waiting-for-an-available-DB.patch
>
>
> Currently when all the DB connections in the pool are used up threads will 
> wait for available connection.  As connections become available they are 
> given to essentially random threads, not the thread that was waiting first.  
> This causes somewhat erratic behavior since some requests will come in and 
> get a connection right away even though others have been waiting for a long 
> time, eventually causing more threads to throw exceptions than may have been 
> necessary if requests were processed in order.  
> Particularly in cases with large but brief spikes in activity - errors may be 
> wholly avoided if requests are processed in order where otherwise they could 
> produce many failures.  I have observed this in my testing.
> I have a patch I am testing out.  It creates a queue to keep track of the 
> waiting threads and then grant them connections in order.



--
This message was sent by Atlassian JIRA
(v6.1#6144)

Reply via email to