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


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. (转)document.cookie.indexof的解释

    代码:function getCookie(c_name){ if(document.cookie.length > 0) { c_start = document.cookie.indexof ...

  2. .net 地址栏传中文乱码 的解决方法

    1.设置web.config文件. <system.web> ...... <globalization requestEncoding="gb2312" res ...

  3. keycode(来自互联网)

  4. MJRefresh(上拉加载下拉刷新)

    整理自:https://github.com/CoderMJLee/MJRefresh#%E6%94%AF%E6%8C%81%E5%93%AA%E4%BA%9B%E6%8E%A7%E4%BB%B6%E ...

  5. iOS 之URL schemes

    添加 URL  schemes 步骤: 1.打开info.plist文件. 2.点击 “+ ”号添加,或者在列表上点击鼠标右键,选择 Add Row. 3.选择 URL types. 4.点击三角号展 ...

  6. C#避免过长的IF和Switch分支的方法

    C#避免过长的IF和Switch分支的方法 1.最蠢形态 //很丑有没有! //这个分支要是一两个还是可以接受的 class Program { static void Main(string[] a ...

  7. 网络编程之TCP

    知识补充:源IP地址和目的IP地址以及源端口号和目的端口号的组合称为套接字.其用于标识客户端请求的服务器和服务. TCP编程的实现步骤:服务器端:1.通过ServletSocket创建绑定到指定客户端 ...

  8. 负载均衡集群之LVS持久链接

    原理--> 通过构建一个hash表,利用CIP与RS的对应关系,来保持来自一个CIP的各种服务都走同一个RS 目的--> 保持持久链接的同时,将多个服务合并起来,例如http和https ...

  9. sleep函数——Gevent源码分析

    gevent是一个异步I/O框架,当遇到I/O操作的时候,会自动切换任务,从而能异步地完成I/O操作 但是在测试的情况下,可以使用sleep函数来让gevent进行任务切换.示例如下: import ...

  10. WSGI的理解

    Python web开发中,服务端程序可分为2个部分: 服务器程序(用来接收.整理客户端发送的请求) 应用程序(处理服务器程序传递过来的请求) 在开发应用程序的时候,我们会把常用的功能封装起来,成为各 ...