Notes for MongoDB/SQL connection pool

Source: Internet
Author: User
Tags mongodb connection string

By default, basically all databases have connection pool items. MongoDB is no exception. When we use consistent connection strings, these connections will be reused in a pool, if the minimum minpoolsize connection pool is not set, these connections will be closed within a certain period of time. When this value is set, the connection pool retains the number of active connections with this value for reuse, this eliminates the need to repeatedly create waste.

Note that the connection string must have the same segment. Otherwise, another pool will be created again. (This is true for SQL and MongoDB ). In the serial process, connections created using the same connection string usually point to the same connection (when there are no other parallel threads ). In the parallel process, minimumpoolsize is recycled in the pool. Different connection strings must create different connections, and a new pool is generated to control the connection.

You may think it is good to have a pool, but the maximumpoolsize of the pool must have a reasonable value. Otherwise, all connections with the data volume will be occupied, and new connections will be created later, the connection cannot exceed the upper limit of the pool to create a new connection. (I remember that when designing the object pool, the design allowed to exceed the limit, but it is unclear whether the database has such settings ). In addition, you must set reasonable connection waits and connection timeout to prevent a connection from occupying too long and affecting other connection requests. Complete MongoDB connection string

Server = 127.0.0.1: 27017; connecttimeout = 500000; connectionlifetime = 400000; minimumpoolsize = 10; maximumpoolsize = 500; pooled = true

Of course, you can also specify the user and password for access like an SQL connection.

the official website introduces that each client to server cannot have more than 100 connections ( at first, the client is a PC, however, subsequent tests show that only one enabled application Program , that is, the same computer can enable multiple identical or different applications with 100 connections in parallel ). The test proves that the maximum number of concurrent connections for a single application is 100 . However, 100 is not maximumpoolsize is an appropriate value, because one PC may have multiple applications (for example, 10 applications) and multiple similar PCs (for example, 1000) connected to the server, therefore, maximumpoolsize may be 100*10*1000 concurrent connections. Therefore, you need to set a reasonable maximumpoolsize Based on the implementation, as well as the waiting time and timeout time for each connection. Note: When a single application program performs parallel operations, the number of parallel connections cannot exceed 100. Although the number of parallel connections per customer cannot exceed 100, Mongo is thread-safe, allows parallel operations on each connection. (Parallel operations are not allowed under a single SQL connection ).

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.