简体   繁体   中英

Procedure takes long time under concurrent requests

Our web-application is under development mode and I have seen a pattern replicate. ie MySQl procedures runtime increases linearly with number of requests.

Our db is pretty small (~500mb). On opening a page, 3 procedures are called in parallel (only read, no write). On a normal run, I have observed that it takes about 0.5 sec for a procedure to run. But interesting thing to observe is that, when 3 users open the page: it takes about 3 seconds to process (ie 9 procedures are called).

For 5 users (ie 15 procedures) about 11 seconds

For 10 users (ie 30 procedures) about 20 seconds

And for more users, it even increases to 40+. After which even if I try connecting my database from mysql workbench or so, it doesn't connect till I restart it. Procedures are all read-only.

I am calling it from Spring JDBC . My config.xml :

//DBCP connection pool settings.
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
    destroy-method="close" p:initialSize="20" p:maxActive="-1" p:minIdle="5"
    p:maxIdle="35" p:driverClassName="com.mysql.jdbc.Driver"
    p:url="jdbc:mysql://10.0.1.100/warehouse?useUnicode=true&amp;"
    p:username="user" p:password="123" p:testOnBorrow="true"
    p:validationQuery="SELECT 1" />
<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
    <property name="dataSource">
        <ref bean="dataSource" />
    </property>
</bean>

Question: Has it got to do with configuring MySQL? Or my DBCP connection pool? What else can be the reason for the behavior?

Question: Has it got to do with configuring MySQL?

Probably not.

Or my DBCP connection pool?

Probably not.

What else can be the reason for the behaviour?

This sounds like the sort of behaviour would would get if the performance of database server was the bottleneck. Such a bottleneck could be due to the server being CPU-bound or disc IO-bound, or if each query required prolonged exclusive access to the same table or set of rows or something.

Another possibility is that the problem is due to a concurrency bottleneck on the client side. For instance if each request did something like this:

  synchronized (someGlobalLock) {
     // perform queries, updates
  }

then you are effectively serializing the execution of the database operations for these requests. That will result in a linear increase in elapsed time when N requests are performed simultaneously.


But to be honest, it is difficult to predict what the cause is without looking in detail at the Java code, the database schema and queries and (maybe) the database configuration.

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