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


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. mvc分页生成静态页,mvc生成静态页

    http://blog.csdn.net/xxj_jing/article/details/7899125 分页生成静态页 http://www.cnblogs.com/luanyilin/archi ...

  2. Volley的三种基本用法StringRequest的Get和post用法以及JsonObjectRequest

    首先做出整个应用的全局请求队列 package com.qg.lizhanqi.myvolleydemo; import android.app.Application; import com.and ...

  3. 1218.1——OC中的常见关键字及一些基本方法

    OC常见的关键字介绍: @ 看到这个关键字,我们就应该想到,这是Object-C对C语言的扩展,例如@interface XXX. @interface 声明类 @implementation 实现类 ...

  4. 序列化类型为“System.Reflection.Module”的对象时检测到循环引用

    在使用ajax调用web services时,正好返回的类型为datatable,想用通过json方式直接解析,但调用后,得到如下错误: 序列化类型为“System.Reflection.Module ...

  5. final+基本类型导致只编译常量类引起的错误

    http://jackyrong.iteye.com/blog/1813878 字节码问题.

  6. 汇编写函数:关于PUBLIC和EXTRN的区别

    PUBLIC伪指令的格式:PUBLIC 标识符,标识符... 该伪指令告诉汇编程序放在PUBLIC之后的标识符(本模块的定义的)可为其他模块使用,这些标识符可以是变量.标号或者过程名.言外之意,它不仅 ...

  7. windbg命令详解

      DLL 该扩展仅在内核模式下使用,即使它是在Ext.dll中的. Windows NT 4.0 Ext.dll Windows 2000 Ext.dll Windows XP和之后 Ext.dll ...

  8. 【转】android是32-bit系统还是64-bit系统

    原文网址:http://www.cnblogs.com/pengwang/archive/2013/03/11/2954496.html 电脑CPU分32位和64位,这个我们都知道.用了这么长时间的a ...

  9. location.href IE6 下不起作用的罪魁祸首

    解决问题 在btn_publish函数内逻辑最后面加:return false;

  10. hdu1166 树状数组

    不知道为什么用C++输入输出死活不过,换成C的就过了... #include <stdio.h> #include <string.h> //================= ...