10

在我们的业务线中,我们托管了一个基于 REST 的 API,该 API 由 Windows Azure 托管,并使用 SQL Azure 作为数据库存储。

Web 角色(Windows 2008R2、IIS 7.5、WCF、大型实例)和 SQL Azure 都托管在北欧地区。

问题是,当我们执行密集的 SQL 工作时,我们经常会收到“超时已过期。在操作完成之前超时时间已过或服务器没有响应”。.

这里让我烦恼的是,无论我们做什么,我们都无法在我们的本地 SQL 服务器(SQL Server 2008R2)上引发这种情况。

感谢任何有助于澄清这个谜团的帮助,因为 Web 角色实例似乎没有直接与 SQL Azure 实例对话,尽管两者都位于北欧。

更详细的例外:

<SqlException>
    <Message>Timeout expired.  The timeout period elapsed prior to completion of the operation or the server is not responding.</Message>
    <StackTrace>
        <Line>at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection)</Line>
        <Line>at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning()</Line>
        <Line>at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)</Line>
        <Line>at System.Data.SqlClient.SqlDataReader.ConsumeMetaData()</Line>
        <Line>at System.Data.SqlClient.SqlDataReader.get_MetaData()</Line>
        <Line>at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString)</Line>
        <Line>at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async)</Line>
        <Line>at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result)</Line>
        <Line>at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)</Line>
        <Line>at System.Data.SqlClient.SqlCommand.ExecuteScalar()</Line>
        <Line>at SyncInvokeAddCollaboratorFieldInstance(Object , Object[] , Object[] )</Line>
        <Line>at System.ServiceModel.Dispatcher.SyncMethodInvoker.Invoke(Object instance, Object[] inputs, Object[]&amp; outputs)</Line>
        <Line>at System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin(MessageRpc&amp; rpc)</Line>
        <Line>at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage5(MessageRpc&amp; rpc)</Line>
        <Line>at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage31(MessageRpc&amp; rpc)</Line>
        <Line>at System.ServiceModel.Dispatcher.MessageRpc.Process(Boolean isOperationContextSet)</Line>
    </StackTrace>
    <UserDefinedInformation>
        <HelpLink.ProdName><![CDATA[Microsoft SQL Server]]></HelpLink.ProdName>
        <HelpLink.ProdVer><![CDATA[11.00.2065]]></HelpLink.ProdVer>
        <HelpLink.EvtSrc><![CDATA[MSSQLServer]]></HelpLink.EvtSrc>
        <HelpLink.EvtID><![CDATA[-2]]></HelpLink.EvtID>
        <HelpLink.BaseHelpUrl><![CDATA[http://go.microsoft.com/fwlink]]></HelpLink.BaseHelpUrl>
        <HelpLink.LinkId><![CDATA[20476]]></HelpLink.LinkId>
    </UserDefinedInformation>
</SqlException>
4

1 回答 1

6

如果您需要执行 SQL 密集型工作(例如,规范化 OLTP 数据库中的大量 INSERT 语句),您需要在代码中包含故障转移逻辑。

本地 SQL 服务器不会受此影响,因此在切换到 SQL Azure 之前要考虑到这一点。

这两篇文章启发了我(特别感谢Joachim Isaksson的指导):

http://blogs.msdn.com/b/sqlazure/archive/2010/05/11/10011247.aspx

http://social.msdn.microsoft.com/Forums/en-US/ssdsgetstarted/thread/7a50985d-92c2-472f-9464-a6591efec4b3/

总而言之,我提供了两个结果,现在结果相同(在某些未添加的记录之前,就原始问题而言,缺少故障转移逻辑:超时已过期):

本地 SQL Server:427 秒内 179.285 条记录

SQL Azure w。故障转移逻辑:179.285 条记录在 2.247 秒内 - 慢了 5.2 倍!

我希望这可以帮助其他在 SQL Azure 中苦苦挣扎的人。积极的一面;您(艰难地)了解到您在本地内部应用程序中很幸运并享有特权:-)

注意:我仍然想解释这是如何发生的......似乎很容易归咎于延迟,不是吗?

于 2012-09-25T17:44:44.017 回答