Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I have used </p> <pre><code>Session session = SessionFactoryUtils.getSession(this.sessionFactory, true); </code></pre> <p>to get session. Above the DAO layer, transaction with annotations (@Transactional) is used in add, edit or delete. Our application uses shiro for authentication and authorization. In each page access, it creates at least 5 connections. So the subsequent request keeps on increasing mysql connection. Thanks to @Venu I found out that </p> <pre><code>show variables like "max_connections"; </code></pre> <p>shows default maximum connection available. Initially (I guess) it was set to 151. This number would soon exhaust because another variable "innodb_open_files" was set to 300. By intuition I can say if one table reaches maximum connection of 300 it would only go for clean up (just like garbage collection in java).</p> <p>One would think, if we would increase the value of "max_connections" to 300 it solve this error, but as I said earlier "innodb_open_files" does not go for cleanup until one table reaches that limit. In our case user table which would be called frequently would reach that limit for cleanup to happen. This means, you cannot know before hand what is the perfect number for "max_connections".</p> <p>In mysql configuration file "/etc/mysql/my.cnf" max_connections is set as</p> <pre><code>max_connections = 1000 </code></pre> <p>I did not change </p> <p>value of "innodb_open_files", which is default to "300"</p> <pre><code>mysql&gt; show variables like "innodb_open_files"; </code></pre> <p>During execution of your program you can use</p> <pre><code>mysql&gt; show processlist; </code></pre> <p>to find out how many connections are open. I guess all the processes in Sleep state can be deleted in next cycle of cleanup (but its only my guess).</p> <p>To simulate more than 1000 users, executing some url in your web project, you can use software like jmeter and set number of thread (users) to 1000. Use of more user also depends upon available RAM in your computer. I was able to simulate more than 3000 connections sending requests at 1 second interval. A good and sufficient tutorial on how to do this is listed on <a href="http://www.roseindia.net/jmeter/" rel="nofollow">roseindia</a></p> <p>Now my query. I have not closed session on any place. I guess @Transaction was created for that purpose (mysql proves that, because all those connections get cleaned once the limit reaches). Due to merge problem of detached objects, I had to used OpenSessionInViewFilter. OpenSessionInViewFilter (can be OpenSessionInViewInterceptor) opens the session a little longer for the merge to happen, which might be the reason so many connections remain open in mysql (Don't know clearly). Since it works for so many users it seems a good solution, but is there a better solution to make it work under default max connection size of mysql. i.e 151 connections.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload