繁体   English   中英

500 - 请求超时

[英]500 - The request timed out

我有一个运行大约 4 分钟 30 秒的脚本,我在我的 aspx 网页的配置页面中将默认超时时间更改为 3600 秒

IIS 上开发版和上传版没有返回 500 - 请求超时错误 8.

但是,当我将它上传到 azure 的实时站点时,它返回 500 - 请求超时错误。

Azure 会覆盖这些设置吗?

配置:

<configuration>
  <system.web>
    <httpRuntime executionTimeout="3600" />
    <sessionState timeout="360" />
    <compilation debug="false" targetFramework="4.0">
      <assemblies>
        <add assembly="System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
        <add assembly="System.Web.Extensions.Design, Version=4.0.0.0, Culture=neutral/>
      </assemblies>
    </compilation>
  </system.web>
</configuration>

编辑:

我将 SCM_COMMAND_IDLE_TIMEOUT 添加到具有 3600 值的 azure 应用程序设置中,但它没有修复错误,现在试图提高我的代码的性能:

原版的:

Stopwatch stopwatch = new Stopwatch();
stopwatch.Start();

Dictionary<int, Dictionary<DateTime, float>> d_PhoneNo_DateDataList = new Dictionary<int, Dictionary<DateTime, float>>();

string sqlcommand = "SELECT ---- FROM ---- INNER JOIN ---- ON ---- = ---- WHERE PhoneNo=@PhoneNo AND date BETWEEN @Date1 AND @Date2";
string strConnectionString = ConfigurationManager.ConnectionStrings["---"].ConnectionString;

using (SqlConnection conn = new SqlConnection(strConnectionString))
{
    Dictionary<DateTime, float> d_DateTime_Data;

    using (SqlCommand cmd = new SqlCommand(sqlcommand, conn))
    {
        cmd.Parameters.Add("@PhoneNo", SqlDbType.Int);
        cmd.Parameters.AddWithValue("@Date1", dateStart);
        cmd.Parameters.AddWithValue("@Date2", dateEnd.AddDays(1));
        conn.Open();

        for (int i = 0; i < phoneNo.Count; i++)
        {
            d_DateTime_Data = new Dictionary<DateTime, float>();
            cmd.Parameters["@PhoneNo"].Value = phoneNo[i];
            cmd.ExecuteNonQuery();
            using (SqlDataReader reader = cmd.ExecuteReader())
            {
                while (reader.Read())
                {
                    d_DateTime_Data.Add(DateTime.Parse(reader["Date"].ToString()), float.Parse(reader["Data"].ToString()));
                }
            }
            d_PhoneNo_DateDataList.Add(phoneNo[i], d_DateTime_Data);
        }
        conn.Close();
    }
}

我尝试将 concurrentDictionary 与 Parallel.For 一起使用,但它会导致 DataReader 出现问题

ConcurrentDictionary<int, Dictionary<DateTime, float>> d_PhoneNo_DateDataList = new ConcurrentDictionary<int, Dictionary<DateTime, float>>();

string sqlcommand = "SELECT ---- FROM ---- INNER JOIN ---- ON ---- = ---- WHERE PhoneNo=@PhoneNo AND date BETWEEN @Date1 AND @Date2";
string strConnectionString = ConfigurationManager.ConnectionStrings["----"].ConnectionString;

using (SqlConnection conn = new SqlConnection(strConnectionString))
{
    Dictionary<DateTime, float> d_DateTime_Data;

    using (SqlCommand cmd = new SqlCommand(sqlcommand, conn))
    {
        cmd.Parameters.Add("@PhoneNo", SqlDbType.Int);
        cmd.Parameters.AddWithValue("@Date1", dateStart);
        cmd.Parameters.AddWithValue("@Date2", dateEnd.AddDays(1));
        conn.Open();

        Parallel.For(0, phoneNo.Count, (index) =>
        {
            d_DateTime_Data = new Dictionary<DateTime, float>();
            cmd.Parameters["@PhoneNo"].Value = phoneNo[index];
            cmd.ExecuteNonQuery();
            using (SqlDataReader reader = cmd.ExecuteReader())
            {
                while (reader.Read())
                {
                    d_DateTime_Data.Add(DateTime.Parse(reader["Date"].ToString()), float.Parse(reader["Data"].ToString()));
                }
            }
            d_PhoneNo_DateDataList.TryAdd(phoneNo[index], d_DateTime_Data);
        });
        conn.Close();
    }
}

如果您的Web应用程序包含需要很长时间的任何代码,那么请将其移至Web作业,至少避免对应用程序可伸缩性产生任何影响。

1-创建Web作业并移动需要很长时间的代码。

2-使Web作业侦听队列

3-在Web应用程序中,用户提交后,在队列中插入包含所需详细信息的消息

4-如果您需要通知用户有关该过程的完成情况,请使用SignalR,从您的JavaScript连接到集线器,并在Web作业代码中发布消息,这将立即通知用户

您最有可能遇到App Service中硬编码的230秒超时。

有关更多信息,请参阅此问
Azure ASP .net WebApp请求超时

尝试将长时间运行的任务作为WebJob,并将结果发布到队列或表。 或者发布到表/ Blob(如果您重复使用数据,甚至可能是Redis)并使用Queue消息发送信号。

当我们使用较旧版本的SDK(2.3)和负载平衡器进行Web服务调用时,我们遇到了与Azure相同的问题。 这可能与您不一样,因为您正在进行数据库查询。 负载均衡器的默认超时为4分钟。 更新到更新版本的SDK并使用idleTimeoutInMinutes的端点设置允许在超时前最多30分钟(我认为)。

行动:

您正在Azure中托管云服务

结果:

您有客户呼叫您的云服务,如果云服务呼叫的时间超过4分钟,那么您的客户就会挂起,直到客户端超时为止。

原因:

Azure云服务负载均衡器中TCP连接的默认空闲超时为4分钟。

解析度:

您需要升级到至少2.4 Azure SDK,然后您可以启用CSDEF文件的idleTimeoutInMinutes属性来控制Azure负载均衡器在重置该连接之前让这些空闲TCP连接保持活动状态的时间。

<Endpoints>
  <InputEndpoint name="Endpoint1" protocol="http" port="80" idleTimeoutInMinutes="6" />
</Endpoints>

新增功能:Azure负载均衡器的可配置空闲超时http://azure.microsoft.com/blog/2014/08/14/new-configurable-idle-timeout-for-azure-load-balancer/

如果您正在使用 Azure Web 应用程序并收到此错误。 这是因为默认情况下,azure 中负载平衡上的 web 应用程序的超时设置为 230 秒,即 3.8 分钟。 如果您的应用程序需要更多时间来响应请求,您会收到此错误。

要解决此问题,请检查您的代码中是否有任何逻辑处理需要很长时间才能完成并返回响应。

暂无
暂无

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

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