"Cicada Hall Learning Notes"--on the understanding and simple establishment of node. JS Access database Connection Pool---@wan <

Source: Internet
Author: User
Tags connection pooling

What is a database connection pool

Official explanation: The database connection pool is responsible for allocating, managing, and releasing database connections, allowing applications to reuse an existing database connection instead of re-establishing one, freeing up database connections that have been idle for more than the maximum idle time to avoid missing database connections due to not releasing the database connection. This technology can significantly improve the performance of database operations.

Personal Understanding: The database connection pool is a buffer between the user request and the database, because in the case of a large number of requests to the database, the frequent creation and shutdown of the connection will severely degrade the performance of the database and server, a buffer is needed to alleviate the burden on the database and the server.

Direct access to the database

Simple database requests each access to create a new connection runs out of close

Using connection pooling

Create a connection pool at the beginning of the program

Request to come in and return data to the request by connecting the pools response

The request is complete and the connection is returned to the connection pool

Disconnect frees resources when exiting a program

Using connection pooling can help us better manage database connections

Here we have the connection pool code for database creation as follows:

Const dbpool={    //Configuration Databaseconfig: {host:"Host Name", Port:"Port number", User:"Database user name", Password:"Database Password", Database:"Database Name"}, DbConnection:function(sqlstr, Sqlarr, fn) {//Create connection pool, pass in config, return linked objectLet Pool=mysql.createpool ( This. config); //get linked objectPool.getconnection (function(err,connection) {if(Err) {Console.log (connection)}//Send Queryconnection.query (sqlstr, Sqlarr, FN); //Close Linkconnection.release (); })    }}//make Dbpool public.Module.exports = Dbpool;

This is a personal understanding of node. js using the connection pool and simple way to establish a connection pool, there are shortcomings, welcome the big guy pointing

"Cicada Hall Learning Notes"--about the understanding and simple establishment of node. JS Access database connection pool [email protected]<

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.