gpt4 book ai didi

c# - Azure 辅助角色响应时间缓慢

转载 作者:行者123 更新时间:2023-12-03 03:15:43 24 4
gpt4 key购买 nike

我使用在 Azure 辅助角色中运行的 OWIN 和 Nancy 创建了一个简单的“Hello World”服务。在本地运行时,我得到的响应时间约为 1 毫秒。一旦我部署它,大约需要 250~400 毫秒。它在单个 Standard_A1 实例上运行。我不认为这是 Nancy 的问题,因为在使用 WebApi 而不是 Nancy 时,我得到了类似的响应时间。我知道这不是我访问它的网络,因为监视器也显示类似的响应时间。

enter image description here

这是我的发布配置文件:

enter image description here

我的 WorkerRole.cs 类如下:

public class WorkerRole : RoleEntryPoint
{
private readonly CancellationTokenSource cancellationTokenSource = new CancellationTokenSource();
private readonly ManualResetEvent runCompleteEvent = new ManualResetEvent(false);
private IDisposable _app = null;

public override void Run()
{
Trace.TraceInformation("StackOverflow.Example is running");

try
{
this.RunAsync(this.cancellationTokenSource.Token).Wait();
}
finally
{
this.runCompleteEvent.Set();
}
}

public override bool OnStart()
{
ServicePointManager.DefaultConnectionLimit = 64;

var endpoint = RoleEnvironment.CurrentRoleInstance.InstanceEndpoints["DefaultEndpoint"];
string baseUri = String.Format("{0}://{1}", endpoint.Protocol, endpoint.IPEndpoint);

Trace.TraceInformation(String.Format("Starting OWIN at {0}", baseUri), "Information");

_app = WebApp.Start<Startup>(new StartOptions(url: baseUri));

bool result = base.OnStart();

Trace.TraceInformation("StackOverflow.Example has been started");

return result;
}

public override void OnStop()
{
Trace.TraceInformation("StackOverflow.Example is stopping");

this.cancellationTokenSource.Cancel();
this.runCompleteEvent.WaitOne();

if (_app != null)
{
_app.Dispose();
}

base.OnStop();

Trace.TraceInformation("StackOverflow.Example has stopped");
}

private async Task RunAsync(CancellationToken cancellationToken)
{
// TODO: Replace the following with your own logic.
while (!cancellationToken.IsCancellationRequested)
{
Trace.TraceInformation("Working");
await Task.Delay(1000);
}
}
}

我的app.config是这样的:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="owin:HandleAllRequests" value="true"/>
</appSettings>
</configuration>

这是 Controller :

public class MonitorController : NancyModule
{
public MonitorController()
: base("/api")
{
Get["/monitor"] = x => "Hello world!";
}
}

关于可能导致这种情况的原因或者我如何尝试找出原因有什么想法吗?

最佳答案

通过 VIP 访问端点与 *cloudapp.net url 修复了此问题。

关于c# - Azure 辅助角色响应时间缓慢,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27574135/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com