简体   繁体   English

如何在ASP.NET上找出max_user_connections | MySQL应用程序?

[英]How can i figure out a max_user_connections on ASP.NET | MySql application?

last year i developed an ASP.NET Application implenting MVP Model. 去年,我开发了一个ASP.NET应用程序MVP模型。 The site is not very large (about 9.000 views/day). 该网站不是很大(每天约有9000次观看)。 It is a common application witch just desplays articles, supports scheduling (via datetime),vote and views, sections and categories. 它是一个普通的应用程序,仅显示文章,支持调度(通过日期时间),投票和视图,节和类别。

From then i create more than 15 sites with the same motive ( The database michanism was build in the same logic). 从那时起,我以相同的动机创建了15个以上的站点(数据库机制以相同的逻辑构建)。

What i did was : Every time a request arrive i have to take articles, sections, categories, views and votes from my Database and display them to the user...like all other web apps. 我所做的是:每次收到请求时,我都必须从数据库中获取文章,栏目,类别,视图和投票,并将其显示给用户……就像所有其他Web应用程序一样。

My database objects are somthing like the above : 我的数据库对象像上面这样:

public class MyObjectDatabaseManager{
       public static string Table = DBTables.ArticlesTable;
       public static string ConnectionString = ApplicationManager.ConnectionString;
       public bool insertMyObject(MyObject myObject){/*.....*/}
       public bool updateMyObject(MyObject myObject){/*.....*/}
       public bool deleteMyObject(MyObject myObject){/*.....*/}
       public MyObject getMyObject(int MyObjectID){/**/}
       public List<MyObject> getMyObjects( int limit, int page, bool OrderBy, bool ASC){/*...*/}
}

When ever i want to communicate to the database i do something like the above 每当我想与数据库进行通信时,我都会执行上述操作

   MySqlConnection myConnection = new MySqlConnection(ConnectionString);
   try
      {
       myConnection.Open();
       MySqlCommand cmd = new MySqlCommand(myQuery,myConnection);
       cmd.Parameters.AddWithValue(...);
       cmd.ExecuteReader(); /* OR */ ExecuteNonQuery();
   }catch(Exception){}
   finally
    {
        if (myConnection != null)
        {
            myConnection.Close();
            myConnection.Dispose();
        }
    }

Two months later i've run into trouble. 两个月后,我遇到了麻烦。

The performance start falling down and the database starts to return errors : max_user_connections 性能开始下降,数据库开始返回错误:max_user_connections

Then i think.. " Let's cache the page " And the start to use Output cache for the pages. 然后我想..“让我们缓存页面”,并开始为页面使用Output缓存。 (not a very sophisticated good idea..) (不是一个非常复杂的好主意。)

12 months later my friend told to me to create a "live" article... an article that can be updated without any delay. 12个月后,我的朋友告诉我创建“实时”文章...可以立即更新的文章。 (from the output cache...) (从输出缓存中...)

Then it came into my mind that : " Why to use cache? joomla etc **doesn't" 然后我想到:“为什么要使用缓存?joomla等**不会”

So...i remove the magic "Output cache" directive... From then i run again into the same problem... MAX_USER_CONNETCTIONS! 所以...我删除了神奇的“输出缓存”指令...从那时起,我再次遇到相同的问题... MAX_USER_CONNETCTIONS! :/ :/

What i'm doing wrong? 我做错了什么?

I know that my code communicates alot with the database but... the connection pooling? 我知道我的代码与数据库进行了大量通信,但是...连接池?

Sorry for my english 对不起我的英语不好

Please...help :/ i have no idea how to figure it out:/ 请...帮助:/我不知道如何解决:/

Thank you. 谢谢。 I'm running into share hosting packet *My db is over 60mb in size* I have more than 6000 rows in some tables like articles *My hosting provider gives me 25 connections to the database (very large number in my opinion)* 遇到了共享托管数据包 *我的数据库大小超过60mb * 我在某些表(如文章)中有6000多行 *我的托管服务提供商为我提供了25个与数据库的连接(我认为数量很大)*

Your code looks fine to me, although from a style perspective I prefer "using" to "try / finally / Dispose()". 您的代码对我来说看起来不错,尽管从样式角度来看,我更喜欢“使用”而不是“ try / finally / Dispose()”。

One thing to check is to make sure that the connection strings you're using are identical, everywhere in your code. 要检查的一件事是确保代码中的所有地方使用的连接字符串都是相同的。 Most DB drivers to connection pooling based on comparing the connection strings. 大多数数据库驱动程序基于比较连接字符串来建立连接池。

You may need to increase the max_connections variable in your mysql config. 您可能需要在mysql配置中增加max_connections变量。

See: 看到:

http://dev.mysql.com/doc/refman/5.5/en/too-many-connections.html http://dev.mysql.com/doc/refman/5.5/en/too-many-connections.html

Actually, Max #/connections is an OS-level configuration. 实际上,Max#/ connections是操作系统级别的配置。

For example, under NT/XP, it was configurable in the registry, under HKLM, ..., TcpIp, Parameters, TcpNumConnections: 例如,在NT / XP下,可以在注册表中的HKLM,...,TcpIp,Parameters,TcpNumConnections下对其进行配置:

http://smallvoid.com/article/winnt-tcpip-max-limit.html http://smallvoid.com/article/winnt-tcpip-max-limit.html

More important, you want to maximum the number of "ephemeral ports" needed to open new connections: 更重要的是,您希望最大程度地打开新连接所需的“临时端口”数量:

http://www.ncftp.com/ncftpd/doc/misc/ephemeral_ports.html http://www.ncftp.com/ncftpd/doc/misc/ephemeral_ports.html

  • Windows: 视窗:

    HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Parameters On the Edit menu, click Add Value, and then add the following registry value: HKEY_LOCAL_MACHINE \\ SYSTEM \\ CurrentControlSet \\ Services \\ Tcpip \\ Parameters在“编辑”菜单上,单击“添加值”,然后添加以下注册表值:

    Value Name: MaxUserPort Data Type: REG_DWORD Value: 65534 值名称:MaxUserPort数据类型:REG_DWORD值:65534

  • Linux: Linux:

    sudo sysctl -w net.ipv4.ip_local_port_range="1024 64000" 须藤sysctl -w net.ipv4.ip_local_port_range =“ 1024 64000”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM