[JAVA-631] Problems with the first query(s) Created: 29/Aug/12 Updated: 11/Sep/19 Resolved: 30/Aug/12 |
|
| Status: | Closed |
| Project: | Java Driver |
| Component/s: | Performance |
| Affects Version/s: | None |
| Fix Version/s: | None |
| Type: | Task | Priority: | Major - P3 |
| Reporter: | Ilya Skorik | Assignee: | Unassigned |
| Resolution: | Done | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Attachments: |
|
| Description |
|
https://groups.google.com/d/topic/mongodb-user/JvlCDGQI65g/discussion In a simple test Java application first query for 3000 elements occurs within 350-400 ms, the second and subsequent occur faster. In the same PHP application query the results are 10-15ms. This is a very serious limitation for web applications. I'm not sure that this is normal behavior for java driver. What could be wrong? |
| Comments |
| Comment by Jeffrey Yemin [ 30/Aug/12 ] |
|
It's not a client OS issue. You just need to increase connectionsPerHost in MongoOptions to ensure there are enough connections to adequately account for the number of threads in the app server that are concurrently using Mongo. |
| Comment by Ilya Skorik [ 30/Aug/12 ] |
|
Thank you all for your participation, the problem with semaphores is probably due to limitations of the client OS. Current level of performance I have more than satisfied. Thank you again! |
| Comment by Scott Hernandez (Inactive) [ 30/Aug/12 ] |
|
Ilya, please make sure connectionsForHost is set to the max number of threads which may be active. that error about semaphores says it is too low. |
| Comment by Jeffrey Yemin [ 30/Aug/12 ] |
|
OK, sounds good. Good luck. |
| Comment by Ilya Skorik [ 30/Aug/12 ] |
|
https://jira.springsource.org/browse/DATAMONGO-520 Spring-data-mongodb issue created, I will try Morphia |
| Comment by Ilya Skorik [ 30/Aug/12 ] |
|
This is 100 request by 100 concurent users in "internet" mode (not flood): Transactions: 973 hits From logs: 11:04:39.615 WARN matrix.webapp.LoginForm - Time for 2725 object is 3201ms All errors (>50%) is a 500 error with "Out of semaphores to get db connection". |
| Comment by Ilya Skorik [ 30/Aug/12 ] |
|
Without Spring-Datat the result is greatly improved, probably a problem with a single request is in the Spring Data code. But there were other interesting questions. This is a log of 100 queries with 1 concurrent user: 10:42:22.456 WARN matrix.webapp.LoginForm - Time for 2725 object is 6ms This is a log of 10 queries with 10 concurrent user: 10:46:50.571 WARN matrix.webapp.LoginForm - Time for 2725 object is 70ms This is a log of 10 queries with 50 concurrent user: 10:47:47.992 WARN matrix.webapp.LoginForm - Time for 2725 object is 763ms This is a log of 10 queries with 100 concurrent user: 0:49:12.875 WARN matrix.webapp.LoginForm - Time for 2725 object is 1596ms And there is problems with stability. There are many (40-50%) error "Out of semaphores to get db connection" – It can be seen that with the increasing competitive connections, query speed degrades linearly and there are errors connecting to the database. Question, this property MongoDB or am I wrong to configure a connection to a database? |
| Comment by Ilya Skorik [ 30/Aug/12 ] |
|
Test controller configuration |
| Comment by Ilya Skorik [ 30/Aug/12 ] |
|
Mongo Object configuration |
| Comment by Jeffrey Yemin [ 30/Aug/12 ] |
|
Just to rule out some unknowns: 1. Perform measurements using System.nanoTime instead of Calendar. More accurate for benchmarking. |
| Comment by Ilya Skorik [ 29/Aug/12 ] |
|
I tested the old applications, generally on my computer Java Web applications work in two to four times more productive than their analogs in PHP. Until then, not to begin to use the Mongo Java Driver. I can not understand what I am wrong and how to fix it. |
| Comment by Ilya Skorik [ 29/Aug/12 ] |
|
Same computer and database, php:
$siege http://localhost:8080/mongotest.php -r 100 -c 10 -i Transactions: 1000 hits
$siege http://localhost:8080/mongotest.php -r 100 -c 10 -b Transactions: 1000 hits
$siege http://localhost:8181/zr-matrix/test/1 -r 100 -c 10 -i Transactions: 1000 hits
$siege http://localhost:8181/zr-matrix/test/1 -r 100 -c 10 -b Transactions: 1000 hits |
| Comment by Ilya Skorik [ 29/Aug/12 ] |
|
Without a query to the Mongo web application handles something about 1200 requests per second with 0,07 ms per request |
| Comment by Ilya Skorik [ 29/Aug/12 ] |
|
done. The results have not changed much. I run the compiled application from war archive in a separate tomcat instance, outside the development environment. Computer - Macbook Pro 13, 2011, with Corei5 and 8Gb Ram, SSD drive. OSX 10.8.1 |
| Comment by Ilya Skorik [ 29/Aug/12 ] |
|
Without sorting |
| Comment by Ilya Skorik [ 29/Aug/12 ] |
|
Without sorting |
| Comment by Jeffrey Yemin [ 29/Aug/12 ] |
|
The PHP and Java apps are performing different queries. The Java app is sorting on a field, and the PHP app is not. Can you make them consistent and retest? |
| Comment by Ilya Skorik [ 29/Aug/12 ] |
|
Jeff, I've tested the application with 1000 transactions, they all are slow. If the problem is in the sockets, what to do, that would increase the speed of five to ten times? |
| Comment by Ilya Skorik [ 29/Aug/12 ] |
|
This is Siege log $siege http://localhost:8181/zr-matrix/test/1 -r 100 -c 10 -i Transactions: 1000 hits Simple controller, a simple test. No operations on the data or complex view. It is normal for Java or I something wrong? |
| Comment by Jeffrey Yemin [ 29/Aug/12 ] |
|
The Mongo instance manages a pool of sockets, which are created lazily, so the first time a thread invokes an operation that needs to interact with the server, the socket will be created and opened, and this operation will be slower as a result. One thing you could try is warming your server before it becomes available for use, thus forcing socket creation. |
| Comment by Ilya Skorik [ 29/Aug/12 ] |
|
This is spring-mvc controller |
| Comment by Ilya Skorik [ 29/Aug/12 ] |
|
Query time log from app |
| Comment by Ilya Skorik [ 29/Aug/12 ] |
|
I'm using spring-mvc and spring-data-mongodb, did everything according to official instructions. According to the logs, the Mongo object is created only once. But each request takes 250-300ms, when a similar php request - 60ms. I do not know how to explain it, and how to fix it. Do you have any ideas? |
| Comment by Jeffrey Yemin [ 29/Aug/12 ] |
|
It's likely because the Java driver lazily opens sockets for each thread on first use of mongo |