为什么我的网站不断冻结?

时间:2022-01-31 08:10:31

This is a pretty vague question and getting it answered seems like a long shot, but I don't know what else to do.

这是一个非常模糊的问题,得到答案似乎是一个长镜头,但我不知道还能做什么。

Ever since I made my website live every now and then it will just freeze. You click on a link and the browser will just site there looking like its trying to connect. It seems the freezing can last up to 2 minutes or so, then everything is just fine. Then a little while later, it will do the same thing.

自从我不时地让我的网站上线以后它就会冻结。您单击一个链接,浏览器将在那里看起来像尝试连接。似乎冻结可以持续长达2分钟左右,然后一切都很好。不久之后,它会做同样的事情。

I track all the exceptions that occur on my website in a log file.

我在日志文件中跟踪我网站上发生的所有异常。

I get these quite a bit ..

我得到了这些......

Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding

超时已过期。操作完成之前经过的超时时间或服务器没有响应

And the stack trace shows it leading to some method that's connecting to the database.

并且堆栈跟踪显示它导致某些连接到数据库的方法。

I'm assuming the freezing has to do with this timeout problem. My website is hosted on a shared server, and my database is on some other server with about a billion other databases as well.

我假设冻结与此超时问题有关。我的网站托管在共享服务器上,我的数据库也在其他服务器上,其他数据库也大约有10亿个。

But even being on a shared server, this freezing problem happens all the time. Its extremely annoying. And I can see this being a pretty catastrophic problem considering my site is ecommerce based and people are doing transactions on it. The last thing I want is the site freezing when my users hit the 'Submit payment' button, then it results in them hitting the submit payment button over and over again because the site froze, then there credit card gets charged about 10 extra times.

但即使是在共享服务器上,这种冻结问题也一直在发生。它非常讨厌。我认为这是一个非常灾难性的问题,因为我的网站是基于电子商务的,人们正在进行交易。我想要的最后一件事就是当我的用户点击“提交付款”按钮时网站冻结,然后导致他们一遍又一遍地点击提交付款按钮,因为网站冻结,然后信用卡被收取大约10次额外费用。

Does anyone have any suggestions on the best way to handle this?

有没有人对处理这个问题的最佳方法有任何建议?

4 个解决方案

#1


Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding

超时已过期。操作完成之前经过的超时时间或服务器没有响应

That's a Sql command timeout exception - it can be somewhat common if your database is under load. Make sure you're disposing of SqlConnections and SqlCommands - though that'd usually result in a pool timeout exception (can't retrieve a connection from the connection pool).

这是一个Sql命令超时异常 - 如果您的数据库处于负载状态,它可能会有些常见。确保您正在处理SqlConnections和SqlCommands - 尽管这通常会导致池超时异常(无法从连接池中检索连接)。

Odds are, someone is running queries that are badly tuned or otherwise sucking resources. It may be your site, but since you're on a shared db server, it could just as easily be someone else's. It could also be blocking, or open transactions - since those would be on your database, that'd be a coding issue. You'll probably need to get your hosting provider involved to track it down or move to a dedicated db server.

可能的情况是,有人正在运行经过严格调整或以其他方式吸收资源的查询。它可能是您的站点,但由于您在共享数据库服务器上,它可能很容易成为其他人的。它也可能是阻塞或打开事务 - 因为那些将存在于您的数据库中,这将是一个编码问题。您可能需要让您的托管服务提供商参与其中以跟踪它或移动到专用数据库服务器。

You can decrease the CommandTimeout of your SqlCommands - I know that sounds somewhat counter-intuitive, but I often find that it's better to fail early than try for 60 seconds throwing additional load on the server. If your .5 second query isn't done in 5 seconds, odds are it won't be done in 60 either.

你可以减少你的SqlCommands的CommandTimeout - 我知道这听起来有些违反直觉,但我经常发现最好早点失败,而不是试着在服务器上投入额外的负载60秒。如果您的.5秒查询未在5秒内完成,则可能性也不会在60秒内完成。

Alternatively, if you're the patient type, you can increase the CommandTimeout - but there's also a IIS timeout of 90 seconds that you'll need to modify if you bump it up too much.

或者,如果您是患者类型,则可以增加CommandTimeout - 但是如果您将其增加太多,则还需要修改90秒的IIS超时。

#2


I am guessing that it has to do with the database connections. Check to see that they are getting released properly? If not then it will use them all up.

我猜它与数据库连接有关。检查一下它们是否正确释放?如果没有,那么它将全部使用它们。

Also check to see if your database has connection pooling configured.

还要检查数据库是否已配置连接池。

#3


The timeout errors is definitely the source of the freezing pages. When it happens the page will wait something like a minute for the database connection before it returns the error message. As the web server only handles one page at a time from each user, the entire site will seem to be frozen for the user until the timeout error comes. Even if it only happens for a few users once in a while, it will seem quite severe to them as they can't access the site at all for a minute or so.

超时错误肯定是冻结页面的来源。当它发生时,页面将在返回错误消息之前等待数据库连接。由于Web服务器一次只处理来自每个用户的一个页面,因此在超时错误发生之前,整个站点似乎都会被冻结。即使它偶尔会发生在一些用户身上,但对他们来说似乎非常严重,因为他们根本无法访问该网站一分钟左右。

How severe the problem really is depends on how many errors you get. From your description it sounds like you get a bit too many to be normal.

问题的严重程度取决于您获得的错误数量。根据你的描述,听起来你有点太多不正常了。

Make sure that all your data readers, command objects and connection objects gets disposed properly, so that you don't leave connections open.

确保正确放置所有数据读取器,命令对象和连接对象,以便不打开连接。

Look for deadlock errors in the log also, as they can cause timeouts. If you have queries that lock each other, you may be able to improve them by changing the order that they use the tables.

在日志中查找死锁错误,因为它们可能导致超时。如果您有相互锁定的查询,则可以通过更改使用表的顺序来改进它们。

#4


Check the SQL Server logs, especially for deadlocks.

检查SQL Server日志,尤其是死锁。

If you have multiple connections open, one might be waiting on a row that is locked by the other.

如果您打开了多个连接,则可能正在等待另一个锁定的行。

#1


Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding

超时已过期。操作完成之前经过的超时时间或服务器没有响应

That's a Sql command timeout exception - it can be somewhat common if your database is under load. Make sure you're disposing of SqlConnections and SqlCommands - though that'd usually result in a pool timeout exception (can't retrieve a connection from the connection pool).

这是一个Sql命令超时异常 - 如果您的数据库处于负载状态,它可能会有些常见。确保您正在处理SqlConnections和SqlCommands - 尽管这通常会导致池超时异常(无法从连接池中检索连接)。

Odds are, someone is running queries that are badly tuned or otherwise sucking resources. It may be your site, but since you're on a shared db server, it could just as easily be someone else's. It could also be blocking, or open transactions - since those would be on your database, that'd be a coding issue. You'll probably need to get your hosting provider involved to track it down or move to a dedicated db server.

可能的情况是,有人正在运行经过严格调整或以其他方式吸收资源的查询。它可能是您的站点,但由于您在共享数据库服务器上,它可能很容易成为其他人的。它也可能是阻塞或打开事务 - 因为那些将存在于您的数据库中,这将是一个编码问题。您可能需要让您的托管服务提供商参与其中以跟踪它或移动到专用数据库服务器。

You can decrease the CommandTimeout of your SqlCommands - I know that sounds somewhat counter-intuitive, but I often find that it's better to fail early than try for 60 seconds throwing additional load on the server. If your .5 second query isn't done in 5 seconds, odds are it won't be done in 60 either.

你可以减少你的SqlCommands的CommandTimeout - 我知道这听起来有些违反直觉,但我经常发现最好早点失败,而不是试着在服务器上投入额外的负载60秒。如果您的.5秒查询未在5秒内完成,则可能性也不会在60秒内完成。

Alternatively, if you're the patient type, you can increase the CommandTimeout - but there's also a IIS timeout of 90 seconds that you'll need to modify if you bump it up too much.

或者,如果您是患者类型,则可以增加CommandTimeout - 但是如果您将其增加太多,则还需要修改90秒的IIS超时。

#2


I am guessing that it has to do with the database connections. Check to see that they are getting released properly? If not then it will use them all up.

我猜它与数据库连接有关。检查一下它们是否正确释放?如果没有,那么它将全部使用它们。

Also check to see if your database has connection pooling configured.

还要检查数据库是否已配置连接池。

#3


The timeout errors is definitely the source of the freezing pages. When it happens the page will wait something like a minute for the database connection before it returns the error message. As the web server only handles one page at a time from each user, the entire site will seem to be frozen for the user until the timeout error comes. Even if it only happens for a few users once in a while, it will seem quite severe to them as they can't access the site at all for a minute or so.

超时错误肯定是冻结页面的来源。当它发生时,页面将在返回错误消息之前等待数据库连接。由于Web服务器一次只处理来自每个用户的一个页面,因此在超时错误发生之前,整个站点似乎都会被冻结。即使它偶尔会发生在一些用户身上,但对他们来说似乎非常严重,因为他们根本无法访问该网站一分钟左右。

How severe the problem really is depends on how many errors you get. From your description it sounds like you get a bit too many to be normal.

问题的严重程度取决于您获得的错误数量。根据你的描述,听起来你有点太多不正常了。

Make sure that all your data readers, command objects and connection objects gets disposed properly, so that you don't leave connections open.

确保正确放置所有数据读取器,命令对象和连接对象,以便不打开连接。

Look for deadlock errors in the log also, as they can cause timeouts. If you have queries that lock each other, you may be able to improve them by changing the order that they use the tables.

在日志中查找死锁错误,因为它们可能导致超时。如果您有相互锁定的查询,则可以通过更改使用表的顺序来改进它们。

#4


Check the SQL Server logs, especially for deadlocks.

检查SQL Server日志,尤其是死锁。

If you have multiple connections open, one might be waiting on a row that is locked by the other.

如果您打开了多个连接,则可能正在等待另一个锁定的行。