提供一份官方的译文。翻译也挺辛苦的!!


6.4 Using Connector/Net with Connection Pooling

6.4在Connector/Net中使用连接池

The Connector/Net supports connection pooling for better performance and scalability with database-intensive applications.  This is enabled by default.  You can turn it off or adjust its performance characteristics using the connection string options Pooling, Connection Reset, Connection Lifetime, Cache Server Properties, Max Pool Size and Min Pool Size.  See Section 6.2, “Creating a Connector/Net Connection String” for further information.

Connector/Ne支持连接池,这样可以使数据库相关的应用程序有更好的性能和可伸缩性。在Conncetor/Net中,连接池特是默认开启的,你也可以通过连接字符串关闭或调整其性能特征。如Connection Reset, Connection Lifetime, Cache Server Properties, Max Pool Size and Min Pool Size。参考6.2节,“创建一个Connetor/NEt连接字符串”了解更多的信息。

Connection pooling works by keeping the native connection to the server live when the client disposes of a MySqlConnection.  Subsequently, if a new MySqlConnection object is opened, it will be created from the connection pool, rather than creating a new native connection.  This improves performance.

连接池的工作原理是,当客户端释放MySqlConnection对象的时候,客户端仍然与数据库服务器保持着连接。随后,如果创建一个新的MySqlConnection对象,它将从连接池中创建,而不是创建一个新的本地连接,这提高了性能。

Guidelines

指南

To work as designed, it is best to let the connection pooling system manage all connections.  Do not create a globally accessible instance of MySqlConnection and then manually open and close it.  This interferes with the way the pooling works and can lead to unpredictable results or even exceptions.

作为设计设计,最好让连接池系统管理所有连接。不要创建一个全局的可访问的MySqlConnection实例,然后手动打开和关闭它,这样会干扰连接池的工作方式,甚至可能导致不可预知的结果或异常。

One approach that simplifies things is to avoid manually creating a MySqlConnection object.  Instead use the overloaded methods that take a connection string as an argument.  Using this approach, Connector/Net will automatically create, open, close and destroy connections, using the connection pooling system for best performance.

一种简化的方法是,避免手动创建MySqlConnection对象,而是使用以连接字符串作为参数的重载方法。使用这种方法, Connector/Ne将自动创建,打开,关闭和销毁连接,使用连接池系统的最佳性能。

Typed Datasets and the MembershipProvider and RoleProvider classes use this approach.  Most classes that have methods that take a MySqlConnection as an argument, also have methods that take a connection string as an argument.  This includes MySqlDataAdapter.

类型化数据集和MembershipProvider 、RoleProvider类使用这种方法。大多数类都有使用MySqlConnection作为参数的方法,同时也有使用连接字符串作为参数的方法。这包括MySqlDataAdapter。

Instead of manually creating MySqlCommand objects, you can use the static methods of the MySqlHelper class.  These take a connection string as an argument, and they fully support connection pooling.

与其手动创建MySqlCommand对象,您可以使用MySqlHelper类的静态方法,这些方法使用连接字符串作为参数,并且他们完全支持连接池。

Resource Usage

资源使用情况

Starting with MySQL Connector/Net 6.2, there is a background job that runs every three minutes and removes connections from pool that have been idle (unused) for more than three minutes.  The pool cleanup frees resources on both client and server side.  This is because on the client side every connection uses a socket, and on the server side every connection uses a socket and a thread.

从MySQL Connector/Net 6.2开始,有一个后台作业,每三分钟,从连接池中删除空闲超过三分钟的连接。连接池同事清理释放客户端和服务器端的资源。这是因为每一个连接在客户端会使用一个套接字,在服务器端同时会使用一个套接字和一个线程。

Prior to this change, connections were never removed from the pool, and the pool always contained the peak number of open connections.  For example, a web application that peaked at 1000 concurrent database connections would consume 1000 threads and 1000 open sockets at the server, without ever freeing up those resources from the connection pool.  Connections, no matter how old, will not be closed if the number of connections in the pool is less than or equal to the value set by the Min Pool Size connection string parameter.(这句真不知道怎么翻译,Min Pool Size应该是Max Pool Size吧??否则翻译起来相互矛盾)

在此之前,连接不会从连接池中删除,所以连接池中的连接数量,一直保持着最大连接数。例如,一个web应用程序,假似达到了1000个数据库并发连接的峰值,这会在服务端消耗1000个Socket连接和1000条线程,虽然已经达到了峰值,也不管这些连接是什么时候创建的,都不会从连接池中释放这些资源。连接,无论多大,如果不会关闭连接池中的数量小于或等于该值最小池大小设置的连接字符串参数。

.Net中如何使用MySql连接池的更多相关文章

  1. tomcat中使用mysql连接池的配置

    1.下载相应的jar包,添加到工程中 需要下载的包主要有commons-pool2-2.2 commons-dbcp2-2.0.1-src commons-dbcp2-2.0.1  commons-c ...

  2. python中实现mysql连接池

    python中实现mysql连接池 import pymysql from DBUtils.PooledDB import PooledDB MYSQL_HOST = 'localhost' USER ...

  3. 如何在 Swoole 中优雅的实现 MySQL 连接池

    如何在 Swoole 中优雅的实现 MySQL 连接池 一.为什么需要连接池 ? 数据库连接池指的是程序和数据库之间保持一定数量的连接不断开, 并且各个请求的连接可以相互复用, 减少重复连接数据库带来 ...

  4. 解决Mysql连接池被关闭 ,hibernate尝试连接不能连接的问题。 (默认mysql连接池可以访问的时间为8小时,如果超过8小时没有连接,mysql会自动关闭连接池。系统发布第二天访问链接关闭问题。

    解决Mysql连接池被关闭  ,hibernate尝试连接不能连接的问题. (默认MySQL连接池可以访问的时间为8小时,如果超过8小时没有连接,mysql会自动关闭连接池. 所以系统发布第二天访问会 ...

  5. Java Mysql连接池配置和案例分析--超时异常和处理

    前言: 最近在开发服务的时候, 发现服务只要一段时间不用, 下次首次访问总是失败. 该问题影响虽不大, 但终究影响用户体验. 观察日志后发现, mysql连接因长时间空闲而被关闭, 使用时没有死链检测 ...

  6. MySQL连接池

    1. using System; using System.Collections; using MySql.Data.MySqlClient; namespace Helper { /// < ...

  7. mysql连接池不能回避的wait timeout问题(转)

    起因 我们的项目组一直在使用albianj作为开发框架在开发应用.使用至今倒也是没有出现很大的问题,但最近加过监控的接口基本上都会在使用一段时间后,突然之间执行数据库操作变得很慢.虽然会变慢,但持续的 ...

  8. 用swoole简单实现MySQL连接池

    MySQL连接池 在传统的网站开发中,比如LNMP模式,由Nginx的master进程接收请求然后分给多个worker进程,每个worker进程再链接php-fpm的master进程,php-fpm再 ...

  9. 实现一个协程版mysql连接池

    实现一个协程版的mysql连接池,该连接池支持自动创建最小连接数,自动检测mysql健康:基于swoole的chanel. 最近事情忙,心态也有点不积极.技术倒是没有落下,只是越来越不想写博客了.想到 ...

随机推荐

  1. ASP.NET MVC 部分视图(转)

    [部分视图] ASP.NET MVC 里的部分视图,相当于 Web Form 里的 User Control.我们的页面往往会有许多重用的地方,可以进行封装重用.使用 部分视图 :  1. 可以简写代 ...

  2. CSS 设计彻底研究(三)深入理解盒子模型

    第三章 深入理解盒子模型 盒子模型是CSS控制页面的基础.需要清楚“盒子”的含义是什么,以及盒子的组成.此外,应该理解DOM的基本概念,以及DOM树是如何与一个HTML文档对应的,在此基础上充分理解“ ...

  3. Emacs入门快捷键

    打开emacs开始一个程序最基本操作: 1.打开Emacs,执行 $ emacs 2.建立一个新的程序文件. 按C-x C-f 然后在屏幕的底部出现minibuffer,光标提示你输入文件名称, 文件 ...

  4. fddd

    <script language="JavaScript" type="text/javascript"> function exportChart ...

  5. cmd下操作mysql

      将mysql 安装目录下 的bin 添加到 windows 环境变量        步骤:        我的电脑 ->高级->环境变量->path->选择一个用户-> ...

  6. 读jquery.cookie.js源码学到的几个技巧

    一.兼容AMD.CommonJS和普通JS的写法 (function (factory) { if (typeof define === 'function' && define.am ...

  7. C#代码实现,确保windows程序只有一个实例(instance)

    static class Program { /// <summary> /// 应用程序的主入口点. /// </summary> [STAThread] static vo ...

  8. BZOJ 1065 奥运物流

    http://www.lydsy.com/JudgeOnline/problem.php?id=1065 思路:由于n个点,有n条边,因此由根就会引出一个环,我们枚举环的长度,在那个长度断开,我们假设 ...

  9. jQuery之事件

    (一).事件列表. 1.blur() 当失去焦点时触发.包括鼠标点击离开和TAB键离开. 2.change() 当元素获取焦点后,值改变失去焦点事触发. 3.click() 当鼠标单击时触发. 4.d ...

  10. Match类

    Regex在匹配的时候,常常会返回一个Match类的对象,今天就来看看怎么玩这个对象. 一.属性 Captures 按从里到外.从左到右的顺序获取由捕获组匹配的所有捕获的集合(如果正则表达式用 Reg ...