.Net中如何使用MySql连接池
提供一份官方的译文。翻译也挺辛苦的!!
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连接池的更多相关文章
- tomcat中使用mysql连接池的配置
1.下载相应的jar包,添加到工程中 需要下载的包主要有commons-pool2-2.2 commons-dbcp2-2.0.1-src commons-dbcp2-2.0.1 commons-c ...
- python中实现mysql连接池
python中实现mysql连接池 import pymysql from DBUtils.PooledDB import PooledDB MYSQL_HOST = 'localhost' USER ...
- 如何在 Swoole 中优雅的实现 MySQL 连接池
如何在 Swoole 中优雅的实现 MySQL 连接池 一.为什么需要连接池 ? 数据库连接池指的是程序和数据库之间保持一定数量的连接不断开, 并且各个请求的连接可以相互复用, 减少重复连接数据库带来 ...
- 解决Mysql连接池被关闭 ,hibernate尝试连接不能连接的问题。 (默认mysql连接池可以访问的时间为8小时,如果超过8小时没有连接,mysql会自动关闭连接池。系统发布第二天访问链接关闭问题。
解决Mysql连接池被关闭 ,hibernate尝试连接不能连接的问题. (默认MySQL连接池可以访问的时间为8小时,如果超过8小时没有连接,mysql会自动关闭连接池. 所以系统发布第二天访问会 ...
- Java Mysql连接池配置和案例分析--超时异常和处理
前言: 最近在开发服务的时候, 发现服务只要一段时间不用, 下次首次访问总是失败. 该问题影响虽不大, 但终究影响用户体验. 观察日志后发现, mysql连接因长时间空闲而被关闭, 使用时没有死链检测 ...
- MySQL连接池
1. using System; using System.Collections; using MySql.Data.MySqlClient; namespace Helper { /// < ...
- mysql连接池不能回避的wait timeout问题(转)
起因 我们的项目组一直在使用albianj作为开发框架在开发应用.使用至今倒也是没有出现很大的问题,但最近加过监控的接口基本上都会在使用一段时间后,突然之间执行数据库操作变得很慢.虽然会变慢,但持续的 ...
- 用swoole简单实现MySQL连接池
MySQL连接池 在传统的网站开发中,比如LNMP模式,由Nginx的master进程接收请求然后分给多个worker进程,每个worker进程再链接php-fpm的master进程,php-fpm再 ...
- 实现一个协程版mysql连接池
实现一个协程版的mysql连接池,该连接池支持自动创建最小连接数,自动检测mysql健康:基于swoole的chanel. 最近事情忙,心态也有点不积极.技术倒是没有落下,只是越来越不想写博客了.想到 ...
随机推荐
- webservice 远程调试配置
在.NET 中已经默认将WEBSERVICE的远程调试功能关闭,有的时候我们需要远程调试程序的时候,就需要打开此功能我们只需在WEBSERVICE的项目的中添web.config的<system ...
- 注册界面设计及实现之(三)SharedPerferences实现数据暂存
开发步骤: 创建一个SharedPerferences接口对象,并使用其putString方法放入相关的公共数据 将验证通过的注册账号写入到该文件中 将数据进行提交 给出客户提示 //Register ...
- c++设计模式之观察者模式
概念:定义对象间的一种一对多的依赖关系,当一个对象的状态发生改变时,所有依赖于它的对象都得到通知并被自动更新. 通常讲就是被观察者向左右观察对象通知其状态的改变,以使得观察者进行相应信息的更新. 代码 ...
- StringList 自定义快速排序
unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms ...
- Dx 1 error; aborting Conversion to Dalvik format failed with error 1
Dx 1 error; aborting Conversion to Dalvik format failed with error 1 问题实质是工程中android.jar包大于一个: 保留一个a ...
- float的理解
1.浮动包裹性——浮动具有让元素按displya:inline-block显示(如果没有设置宽度和高度,则它可以显示的尽量窄高 度尽量小).2.浮动破坏性——浮动元素漂浮在标准流之上(但没有脱离文档流 ...
- JS控制文本框中的密码显示/隐藏功能
<html> <head> <title>[荐]JS控制文本框中的密码显示/隐藏功能_网页代码站(www.6a8a.com)</title> <s ...
- HTML5简单入门系列(八)
前言 本篇介绍HTML5中相对复杂的一些APIs,其中的数学知识比较多.虽然如此,但是其实API使用起来还是比较方便的. 这里说明一下,只写出API相关的JS代码,因为他们都是基于一个canvas标签 ...
- java使用dom4j和XPath解析XML与.net 操作XML小结
最近研究java的dom4j包,使用 dom4j包来操作了xml 文件 包括三个文件:studentInfo.xml(待解析的xml文件), Dom4jReadExmple.java(解析的主要类), ...
- MVC5学习相关资源整理
1 官方 Getting Started http://www.asp.net/mvc/tutorials/mvc-5/introduction/getting-started 英文不好,英文好的同 ...