新书推介:《语义网技术体系》
作者:瞿裕忠,胡伟,程龚
   XML论坛     W3CHINA.ORG讨论区     计算机科学论坛     SOAChina论坛     Blog     开放翻译计划     新浪微博  
 
  • 首页
  • 登录
  • 注册
  • 软件下载
  • 资料下载
  • 核心成员
  • 帮助
  •   Add to Google

    >> 本版讨论.NET,C#,ASP,VB技术
    [返回] 中文XML论坛 - 专业的XML技术讨论区计算机技术与应用『 Dot NET,C#,ASP,VB 』 → [合集] 在数据库编程中 如何解决  大量用户访问问题? 查看新帖用户列表

      发表一个新主题  发表一个新投票  回复主题  (订阅本版) 您是本帖的第 3593 个阅读者浏览上一篇主题  刷新本主题   树形显示贴子 浏览下一篇主题
     * 贴子主题: [合集] 在数据库编程中 如何解决  大量用户访问问题? 举报  打印  推荐  IE收藏夹 
       本主题类别:     
     admin 帅哥哟,离线,有人找我吗?
      
      
      
      威望:9
      头衔:W3China站长
      等级:计算机硕士学位(管理员)
      文章:5255
      积分:18406
      门派:W3CHINA.ORG
      注册:2003/10/5

    姓名:(无权查看)
    城市:(无权查看)
    院校:(无权查看)
    给admin发送一个短消息 把admin加入好友 查看admin的个人资料 搜索admin在『 Dot NET,C#,ASP,VB 』的所有贴子 点击这里发送电邮给admin  访问admin的主页 引用回复这个贴子 回复这个贴子 查看admin的博客楼主
    发贴心情 [合集] 在数据库编程中 如何解决  大量用户访问问题?


    发信人: Nineteen (-_-#!), 信区: DotNET
    标  题: [合集] 在数据库编程中 如何解决  大量用户访问问题?
    发信站: BBS 水木清华站 (Wed Dec  3 20:12:32 2003), 站内

    ☆─────────────────────────────────────☆
       peakkid (valley) 于  (Tue Dec  2 16:34:09 2003)  提到:

    好像一般的connection连接方式的编程的话
    当用户激增时(如100用户同时在线访问数据库)
    数据库可能就没办法响应了
    请问有什么办法解决这个问题?

    数据库连结池?



    ☆─────────────────────────────────────☆
       archon (酸酸酸) 于  (Tue Dec  2 16:47:59 2003)  提到:


    连接池。

    【 在 peakkid (valley) 的大作中提到: 】
    ∶好像一般的connection连接方式的编程的话
    ∶当用户激增时(如100用户同时在线访问数据库)
    ∶数据库可能就没办法响应了
    ∶请问有什么办法解决这个问题?
    ∶数据库连结池?




    ☆─────────────────────────────────────☆
       peakkid (valley) 于  (Tue Dec  2 16:54:46 2003)  提到:

    能不能说得详细些?nbsp;
    或者哪里有着法方面的文档?
    3x

    btw:你的签名档好熟啊
    【 在 archon (酸酸酸) 的大作中提到: 】
    ∶连接池。




    ☆─────────────────────────────────────☆
       archon (酸酸酸) 于  (Tue Dec  2 17:08:28 2003)  提到:


    msdn里面有个sample,你查index: ConnectionPooling sample

    .NET Samples - How To: Data and ADO.NET

    ConnectionPooling Sample
    This sample illustrates how to construct a pool of connections to a data source. In this sample, the pool is established in the connection string and managed automatically by the SqlConnection.


    btw: 熟就对了


    【 在 peakkid (valley) 的大作中提到: 】
    ∶能不能说得详细些?nbsp;
    ∶或者哪里有着法方面的文档?
    ∶3x
    ∶btw:你的签名档好熟啊




    ☆─────────────────────────────────────☆
       tfe (他乡的爸爸) 于  (Tue Dec  2 17:20:58 2003)  提到:

    可否讲解一下。
    没用过这东东。

    【 在 archon (酸酸酸) 的大作中提到: 】
    ∶连接池。




    ☆─────────────────────────────────────☆
       sdfj (木亦--落霞孤鹜) 于  (Tue Dec  2 17:38:53 2003)  提到:

    http://chs.gotdotnet.com/QuickStart/aspplus/default.aspx?url=%2fquickstart%2fh
    owto%2fdoc%2fadoplus%2fconnectionpooling.aspx
    【 在 tfe (他乡的爸爸) 的大作中提到: 】
    ∶可否讲解一下。
    ∶没用过这东东。




    ☆─────────────────────────────────────☆
       peakkid (valley) 于  (Tue Dec  2 17:49:33 2003)  提到:

    在请教一下
    这个例子中
    我还是看不出来要使用连结池中的连接该怎么做啊


    如何分辨一个连接是连接池中的还是之外的呢?

    是不是一定要先open,再close,再open?

    sorry,hehe问题太弱了
    还望赐教


    connString = "server=(local)\\VSdotNET;Trusted_Connection=yes;database=northwind;" +
                 "connection reset=false;" +
                 "connection lifetime=5;" +
                 "min pool size=1;" +
                 "max pool size=50";

    SqlConnection myConnection1 = new SqlConnection(connString);
    SqlConnection myConnection2 = new SqlConnection(connString);
    SqlConnection myConnection3 = new SqlConnection(connString);


    Dim connString as String

    ' Specification in the connection string:
    ' Please note: Pooling is implicit, you automatically get it unless you disable it.  
    '              Therefore, "true" is the default for the pooling keyword (pooling=true).    
    ' Connection Reset:    False
    ' Connection Lifetime: 5
    ' Enlist:              true
    ' Min Pool Size:       1
    ' Max Pool Size:       50

    connString = "server=(local)\VSdotNET;Trusted_Connection=yes;database=northwind;" & _
                 "connection reset=false;" & _
                 "connection lifetime=5;" & _
                 "enlist=true;" & _
                 "min pool size=1;" & _
                 "max pool size=50"

    Dim myConnection1 as SqlConnection = new SqlConnection(connString)
    Dim myConnection2 as SqlConnection = new SqlConnection(connString)
    Dim myConnection3 as SqlConnection = new SqlConnection(connString)

      
    C#  VB     


    现在,我们有了使用池中的若干连接的代码。首先,打开两个连接并返回这两个到池的连接。然后,从池中打开三个连接,并返回所有这三个到池的连接。  


    // Open two connections. One is from the pool (see min pool size), the other is created.
    Console.WriteLine ("Open two connections.");
    myConnection1.Open();
    myConnection2.Open();

    // Now there are two connections in the pool that matches the connection string.
    // Return the both connections to the pool.  
    Console.WriteLine ("Return both of the connections to the pool.");
    myConnection1.Close();
    myConnection2.Close();

    // Get a connection out of the pool.
    Console.WriteLine ("Open a connection from the pool.");
    myConnection1.Open();

    // Get a second connection out of the pool.
    Console.WriteLine ("Open a second connection from the pool.");
    myConnection2.Open();

    // Open a third connection.
    Console.WriteLine ("Open a third connection.");
    myConnection3.Open();

    // Return the all connections to the pool.   
    Console.WriteLine ("Return all three connections to the pool.");
    myConnection1.Close();
    myConnection2.Close();
    myConnection3.Close();


    ' Open two connections. One is from the pool (see min pool size), the other is created.
    Console.WriteLine ("Open two connections.")
    myConnection1.Open()
    myConnection2.Open()

    ' Now there are two connections in the pool that matches the connection string.
    ' Return the both connections to the pool.  
    Console.WriteLine ("Return both of the connections to the pool.")
    myConnection1.Close()
    myConnection2.Close()

    ' Get a connection out of the pool.
    Console.WriteLine ("Open a connection from the pool.")
    myConnection1.Open()

    ' Get a second connection out of the pool.
    Console.WriteLine ("Open a second connection from the pool.")
    myConnection2.Open()

    ' Open a third connection.
    Console.WriteLine ("Open a third connection.")
    myConnection3.Open()

    ' Return the all connections to the pool.   
    Console.WriteLine ("Return all three connections to the pool.")
    myConnection1.Close()
    myConnection2.Close()
    myConnection3.Close()

      

    【 在 sdfj (木亦--落霞孤鹜) 的大作中提到: 】
    ∶http://chs.gotdotnet.com/QuickStart/aspplus/default.aspx?url=%2fquickstart%2fh
    ∶owto%2fdoc%2fadoplus%2fconnectionpooling.aspx




    ☆─────────────────────────────────────☆
       tfe (他乡的爸爸) 于  (Tue Dec  2 17:51:33 2003)  提到:

    在偶看来他只是建了几个同样的连接。
    提高性能也有限。
    是不是偶太菜了。:(

    【 在 sdfj (木亦--落霞孤鹜) 的大作中提到: 】
    ∶http://chs.gotdotnet.com/QuickStart/aspplus/default.aspx?url=%2fquickstart%2fh
    ∶owto%2fdoc%2fadoplus%2fconnectionpooling.aspx




    ☆─────────────────────────────────────☆
       tfe (他乡的爸爸) 于  (Tue Dec  2 17:52:37 2003)  提到:

    先op再cl再op
    ]系统会告诉你什么?
    偶更菜 了:)

    【 在 peakkid (valley) 的大作中提到: 】
    ∶在请教一下
    ∶这个例子中
    ∶我还是看不出来要使用连结池中的连接该怎么做啊
    ∶如何分辨一个连接是连接池中的还是之外的呢?
    ∶是不是一定要先open,再close,再open?
    ∶sorry,hehe问题太弱了
    ∶还望赐教
    ∶connString = "server=(local)\\VSdotNET;Trusted_Connection=yes;database=northwind;" +
    ∶"connection reset=false;" +
    ∶"connection lifetime=5;" +
    ∶"min pool size=1;" +
    ∶...................



    ☆─────────────────────────────────────☆
       vrsunboy (青杉) 于  (Tue Dec  2 18:12:48 2003)  提到:

    源码里面有这么一些注释:
    Please note: Pooling is implicit, you automatically get it unless you disable it.  
          //              Therefore, "true" is the default for the pooling keyword (pooling=true).    
          // Connection Reset:    False
          // Connection Lifetime: 5
          // Enlist:              true
          // Min Pool Size:       1
          // Max Pool Size:       50
    pooling在default情况下视true的
    一个Sqlconnection默认就使用了pooling技术?
    【 在 archon (酸酸酸) 的大作中提到: 】

    msdn里面有个sample,你查index: ConnectionPooling sample

    .NET Samples - How To: Data and ADO.NET

    ConnectionPooling Sample
    This sample illustrates how to construct a pool of connections to a data source. In this sample, the pool is established in the connection string and managed automatically by the SqlConnection.


    btw: 熟就对了


    【 在 peakkid (valley) 的大作中提到: 】
    ∶能不能说得详细些?nbsp;
    ∶或者哪里有着法方面的文档?
    ∶3x
    ∶btw:你的签名档好熟啊




    ☆─────────────────────────────────────☆
       bigwhitebear (风云惊震因我在,天地愁惨因尔来) 于  (Tue Dec  2 18:59:29 2003)  提到:

    建立池连接可以显著提高应用程序的性能和可缩放性。SQL Server .NET Framework
    数据提供程序自动为 ADO.NET 客户端应用程序提供连接池。您也可以提供几个连接
    字符串修饰符来控制连接池行为,请参见本主题内下文中“使用连接字符串关键字控
    制连接池”这一节。

    池的创建和分配
    当连接打开时,将根据一种精确的匹配算法来创建连接池,该算法会使连接池与连接
    中的字符串相关联。每个连接池都与一个不同的连接字符串相关联。当新连接打开时
    ,如果连接字符串不精确匹配现有池,则将创建一个新池。

    在以下示例中,将创建三个新的 SqlConnection 对象,但只需要使用两个连接池来
    管理这些对象。请注意,第一个和第二个连接字符串的差异在于为 Initial Catalog
    分配的值。

    SqlConnection conn = new SqlConnection();
    conn.ConnectionString = "Integrated Security=SSPI;Initial Catalog=northwind
    ";
    conn.Open();       
    // Pool A is created.

    SqlConnection conn = new SqlConnection();
    conn.ConnectionString = "Integrated Security=SSPI;Initial Catalog=pubs";
    conn.Open();       
    // Pool B is created because the connection strings differ.

    SqlConnection conn = new SqlConnection();
    conn.ConnectionString = "Integrated Security=SSPI;Initial Catalog=northwind
    ";
    conn.Open();       
    // The connection string matches pool A.
    连接池一旦创建,直到活动进程终止时才会被毁坏。非活动或空池的维护只需要最少
    的系统开销。

    连接的添加
    连接池是为每个唯一的连接字符串创建的。当创建一个池后,将创建多个连接对象并
    将其添加到该池中,以满足最小池大小的要求。连接将根据需要添加到池中,直至达
    到最大池大小。

    当请求 SqlConnection 对象时,如果存在可用的连接,则将从池中获取该对象。若
    要成为可用连接,该连接当前必须未被使用,具有匹配的事务上下文或者不与任何事
    务上下文相关联,并且具有与服务器的有效链接。

    如果已达到最大池大小且不存在可用的连接,则该请求将会排队。当连接被释放回池
    中时,连接池管理程序通过重新分配连接来满足这些请求。对 Connection 调用 Close
    或 Dispose 时,连接被释放回池中。

    警告   建议使用完 Connection 后始终将其关闭,以便连接可以返回到池中。这可
    以使用 Connection 对象的 Close 或 Dispose 方法来实现。不是显式关闭的连接可
    能不会添加或返回到池中。例如,如果连接已超出范围但没有显式关闭,则仅当达到
    最大池大小而该连接仍然有效时,该连接才会返回到连接池中。
    注意   不要在类的 Finalize 方法中对 Connection、DataReader 或任何其他托管
    对象调用 Close 或 Dispose。在终结器中,仅释放类直接拥有的非托管资源。如果
    类不拥有任何非托管资源,则不要在类定义中包含 Finalize 方法。有关更多信息,
    请参见垃圾回收编程。
    连接的移除
    如果连接生存期已过期,或者连接池管理程序检测到与服务器的连接已断开,连接池
    管理程序将从池中移除该连接。请注意,只有在尝试与服务器进行通信后,才可以检
    测到这种情况。如果发现某连接不再连接到服务器,则会将其标记为无效。连接池管
    理程序会定期扫描连接池,查找已释放到池中并标记为无效的对象。找到后,这些连
    接将被永久移除。

    如果存在与已消失的服务器的连接,那么即使连接池管理程序未检测到已断开的连接
    并将其标记为无效,仍有可能将此连接从池中取出。当发生这种情况时,将生成异常
    。但是,为了将该连接释放回池中,仍必须将其关闭。

    事务支持
    连接是根据事务上下文来从池中取出并进行分配的。请求线程和所分配的连接的上下
    文必须匹配。因此,每个连接池实际上又分为不具有关联事务上下文的连接以及 N  
    个各自包含与一个特定事务上下文的连接的子部分。

    当连接关闭时,它将被释放回池中,并根据其事务上下文放入相应的子部分。因此,
    即使分布式事务仍然挂起,仍可以关闭该连接而不会生成错误。这样,您就可以在随
    后提交或中止分布式事务。

    使用连接字符串关键字控制连接池
    SqlConnection 对象的 ConnectionString 属性支持连接字符串键/值对,这些键/值
    对可用于调整连接池逻辑的行为。

    下表描述了可用于调整连接池行为的 ConnectionString 值。

    名称 默认值 说明  
    Connection Lifetime 0 当连接返回到池中时,将对它的创建时间和当前时间进行比
    较,如果时间间隔超过由 Connection Lifetime 指定的值(以秒为单位),则会毁
    坏该连接。在聚集配置中可以使用它来强制在运行服务器和刚联机的服务器之间达到
    负载平衡。  
    如果值为零 (0),则将使池连接具有最大的超时期限。
      
    Connection Reset 'true' 确定在从池中移除数据库连接时是否将其重置。对于 Microsoft
    SQL Server 版本 7.0,如果设置为 false,将避免在获取连接时经历一个额外的往
    返过程,但必须注意的是连接状态(如数据库上下文)不会被重置。  
    Enlist 'true' 当为 true 时,如果存在事务上下文,池管理程序将自动在创建线程
    的当前事务上下文中登记连接。  
    Max Pool Size 100 池中允许的最大连接数。  
    Min Pool Size 0 池中维护的最小连接数。  
    Pooling 'true' 当为 true 时,将从相应的池中取出连接,或者在必要时创建连接
    并将其添加到相应的池中。  

    连接池的性能计数器
    SQL Server .NET Framework 数据提供程序添加了几个性能计数器,它们将使您能够
    微调连接池特性,检测与失败的连接尝试相关的间歇性问题,并检测与对 SQL Server
    的超时请求相关的问题。

    下表列出了可以在“.NET CLR 数据”性能对象下的“性能监视器”中访问的连接池
    计数器。

    计数器 说明  

    SqlClient: Current # pooled and non pooled connections 当前池连接或非池连
    接的数目。  
    SqlClient: Current # pooled connections 当前所有池中与特定进程关联的连接的
    数目。  
    SqlClient: Current # connection pools 当前与特定进程关联的池的数目。  
    SqlClient: Peak # pooled connections 自特定进程开始以来所有池中的连接数峰
    值。请注意:此计数器只有在与特定进程实例关联时才可用。_Global 实例始终返回
    0。  
    SqlClient: Total # failed connects 打开连接的尝试因任何原因而失败的总次数
    。  

    注意   将 SQL Server .NET Framework 数据提供程序性能计数器与 ASP.NET 应用
    程序一起使用时,只有 _Global 实例是可用的。因此,性能计数器返回的值是所有
    ASP.NET 应用程序的计数器值的总和。

    【 在 vrsunboy (青杉) 的大作中提到: 】
    ∶源码里面有这么一些注释:
    ∶Please note: Pooling is implicit, you automatically get it unless you disable it.  
    ∶//              Therefore, "true" is the default for the pooling keyword (pooling=true).    
    ∶// Connection Reset:    False
    ∶// Connection Lifetime: 5
    ∶// Enlist:              true
    ∶// Min Pool Size:       1
    ∶// Max Pool Size:       50
    ∶pooling在default情况下视true的
    ∶一个Sqlconnection默认就使用了pooling技术?
    ∶msdn里面有个sample,你查index: ConnectionPooling sample
    ∶...................



    ☆─────────────────────────────────────☆
       bigwhitebear (风云惊震因我在,天地愁惨因尔来) 于  (Tue Dec  2 19:01:39 2003)  提到:

    其实我觉得你的问题不在于技术,而在于服务器的性能
    【 在 peakkid (valley) 的大作中提到: 】
    ∶好像一般的connection连接方式的编程的话
    ∶当用户激增时(如100用户同时在线访问数据库)
    ∶数据库可能就没办法响应了
    ∶请问有什么办法解决这个问题?
    ∶数据库连结池?




    ☆─────────────────────────────────────☆
       bastywinter (basty) 于  (Tue Dec  2 20:08:41 2003)  提到:

    connection pool
    【 在 peakkid (valley) 的大作中提到: 】
    ∶好像一般的connection连接方式的编程的话
    ∶当用户激增时(如100用户同时在线访问数据库)
    ∶数据库可能就没办法响应了
    ∶请问有什么办法解决这个问题?

    ∶数据库连结池?




    ☆─────────────────────────────────────☆
       yyyyyu (zig) 于  (Wed Dec  3 18:55:24 2003)  提到:

    ADO.NET内置connection pool
    【 在 peakkid (valley) 的大作中提到: 】
    ∶能不能说得详细些?nbsp;
    ∶或者哪里有着法方面的文档?
    ∶3x
    ∶btw:你的签名档好熟啊




    上一篇
    返回上一页
    回到目录
    回到页首
    下一篇


       收藏   分享  
    顶(0)
      




    ----------------------------------------------

    -----------------------------------------------

    第十二章第一节《用ROR创建面向资源的服务》
    第十二章第二节《用Restlet创建面向资源的服务》
    第三章《REST式服务有什么不同》
    InfoQ SOA首席编辑胡键评《RESTful Web Services中文版》
    [InfoQ文章]解答有关REST的十点疑惑

    点击查看用户来源及管理<br>发贴IP:*.*.*.* 2004/11/9 2:26:00
     
     xmzhy 帅哥哟,离线,有人找我吗?狮子座1978-8-18
      
      
      威望:5
      等级:计算机学士学位
      文章:385
      积分:2003
      门派:XML.ORG.CN
      注册:2003/10/22

    姓名:(无权查看)
    城市:(无权查看)
    院校:(无权查看)
    给xmzhy发送一个短消息 把xmzhy加入好友 查看xmzhy的个人资料 搜索xmzhy在『 Dot NET,C#,ASP,VB 』的所有贴子 引用回复这个贴子 回复这个贴子 查看xmzhy的博客2
    发贴心情 
    不错
    点击查看用户来源及管理<br>发贴IP:*.*.*.* 2004/12/27 17:14:00
     
     GoogleAdSense狮子座1978-8-18
      
      
      等级:大一新生
      文章:1
      积分:50
      门派:无门无派
      院校:未填写
      注册:2007-01-01
    给Google AdSense发送一个短消息 把Google AdSense加入好友 查看Google AdSense的个人资料 搜索Google AdSense在『 Dot NET,C#,ASP,VB 』的所有贴子 访问Google AdSense的主页 引用回复这个贴子 回复这个贴子 查看Google AdSense的博客广告
    2024/5/10 21:14:31

    本主题贴数2,分页: [1]

    管理选项修改tag | 锁定 | 解锁 | 提升 | 删除 | 移动 | 固顶 | 总固顶 | 奖励 | 惩罚 | 发布公告
    W3C Contributing Supporter! W 3 C h i n a ( since 2003 ) 旗 下 站 点
    苏ICP备05006046号《全国人大常委会关于维护互联网安全的决定》《计算机信息网络国际联网安全保护管理办法》
    109.375ms