首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Azure ML web服务超时

Azure ML web服务超时
EN

Stack Overflow用户
提问于 2015-06-30 05:57:37
回答 3查看 1.7K关注 0票数 2

我在Azure中创建了一个简单的实验,并使用一个http客户机触发它。在Azure ML工作区中,执行时一切正常。但是,当我使用http客户端触发实验时,实验超时并失败。为http客户端设置超时值似乎不起作用。

我们是否可以设置这个超时值,这样实验就不会失败?

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2018-04-01 17:33:08

看起来不可能基于截至2018年4月1日仍被标记为“计划”的特性请求设置这个超时。

2017年开始的MSDN论坛的建议是使用批执行服务,该服务启动机器学习实验,然后异步询问是否已经完成。

下面是Azure ML Web服务管理示例代码的代码片段(所有注释都来自它们的示例代码):

代码语言:javascript
运行
复制
        using (HttpClient client = new HttpClient())
        {
            var request = new BatchExecutionRequest()
            {

                Outputs = new Dictionary<string, AzureBlobDataReference> () {
                    {
                        "output",
                        new AzureBlobDataReference()
                        {
                            ConnectionString = storageConnectionString,
                            RelativeLocation = string.Format("{0}/outputresults.file_extension", StorageContainerName) /*Replace this with the location you would like to use for your output file, and valid file extension (usually .csv for scoring results, or .ilearner for trained models)*/
                        }
                    },
                },    

                GlobalParameters = new Dictionary<string, string>() {
                }
            };

            client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", apiKey);

            // WARNING: The 'await' statement below can result in a deadlock
            // if you are calling this code from the UI thread of an ASP.Net application.
            // One way to address this would be to call ConfigureAwait(false)
            // so that the execution does not attempt to resume on the original context.
            // For instance, replace code such as:
            //      result = await DoSomeTask()
            // with the following:
            //      result = await DoSomeTask().ConfigureAwait(false)

            Console.WriteLine("Submitting the job...");

            // submit the job
            var response = await client.PostAsJsonAsync(BaseUrl + "?api-version=2.0", request);

            if (!response.IsSuccessStatusCode)
            {
                await WriteFailedResponse(response);
                return;
            }

            string jobId = await response.Content.ReadAsAsync<string>();
            Console.WriteLine(string.Format("Job ID: {0}", jobId));

            // start the job
            Console.WriteLine("Starting the job...");
            response = await client.PostAsync(BaseUrl + "/" + jobId + "/start?api-version=2.0", null);
            if (!response.IsSuccessStatusCode)
            {
                await WriteFailedResponse(response);
                return;
            }

            string jobLocation = BaseUrl + "/" + jobId + "?api-version=2.0";
            Stopwatch watch = Stopwatch.StartNew();
            bool done = false;
            while (!done)
            {
                Console.WriteLine("Checking the job status...");
                response = await client.GetAsync(jobLocation);
                if (!response.IsSuccessStatusCode)
                {
                    await WriteFailedResponse(response);
                    return;
                }

                BatchScoreStatus status = await response.Content.ReadAsAsync<BatchScoreStatus>();
                if (watch.ElapsedMilliseconds > TimeOutInMilliseconds)
                {
                    done = true;
                    Console.WriteLine(string.Format("Timed out. Deleting job {0} ...", jobId));
                    await client.DeleteAsync(jobLocation);
                }
                switch (status.StatusCode) {
                    case BatchScoreStatusCode.NotStarted:
                        Console.WriteLine(string.Format("Job {0} not yet started...", jobId));
                        break;
                    case BatchScoreStatusCode.Running:
                        Console.WriteLine(string.Format("Job {0} running...", jobId));
                        break;
                    case BatchScoreStatusCode.Failed:
                        Console.WriteLine(string.Format("Job {0} failed!", jobId));
                        Console.WriteLine(string.Format("Error details: {0}", status.Details));
                        done = true;
                        break;
                    case BatchScoreStatusCode.Cancelled:
                        Console.WriteLine(string.Format("Job {0} cancelled!", jobId));
                        done = true;
                        break;
                    case BatchScoreStatusCode.Finished:
                        done = true;
                        Console.WriteLine(string.Format("Job {0} finished!", jobId));
                        ProcessResults(status);
                        break;
                }

                if (!done) {
                    Thread.Sleep(1000); // Wait one second
                }
            }
        }
票数 0
EN

Stack Overflow用户

发布于 2015-07-06 03:18:09

确保正确设置了客户端超时值。如果服务器启动web服务超时,那么它将用HTTP代码504 BackendScoreTimeout (或者可能是409 GatewayTimeout)返回一个响应。但是,如果您根本没有收到任何回复,那么您的客户等待的时间就不够长。

通过在ML中运行您的实验,您可以找到大量的时间。转到实验属性,找出它运行了多长时间,然后用大约两倍的时间作为超时值。

票数 1
EN

Stack Overflow用户

发布于 2015-12-15 12:28:53

在作为web服务发布的Azure实验中,我也遇到过类似的问题。大多数情况下,它运行正常,而有时返回时会出现超时错误。问题是实验本身有一个90秒的运行时间限制。因此,很可能您的实验运行时间超过了这个限制,并返回了一个超时错误。hth

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/31130629

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档