Bot responses with lag after certain time of non-use

核能气质少年 提交于 2019-12-11 06:08:42

问题


I have a permanent problem which I couldn't solve.
Seems my dll was unloaded from the memory after a while.
For example, when I do not use bot during 30 minutes, and then reuse, it takes some time before responding, like it was re-deployed or dll was no longer in the RAM and it was reloaded before response.
Is there a way to fix the lag when bot is not used for a while?

update :3/1/17

To activate the option ' Always on ', it is necessary to pass on a paying offer. As I am still there dev, I cannot pass on this offer. I found a solution to keep my Bot in alive mode by creating a script that will send messages every minute. My script is in c# and when I execute this, I obtain an error of authorisation.

var authValue = new AuthenticationHeaderValue("Basic", Convert.ToBase64String(Encoding.UTF8.GetBytes($"{MyMicrosoftAppId}:{MyMicrosoftAppPassword}")));

   var client = new HttpClient()
    {
        DefaultRequestHeaders = { Authorization = authValue }

    };

    var jsonObject = new Rootobject()
    {
      type = "message",
      id = "0a24ca1428074419a1679b37e0e3dd39",
      timestamp = DateTime.Now,
      serviceUrl = "http://localhost:9000/",
      channelId = "emulator",
      from = new From()
      {
          id = "2c1c7fa3",
          name = "User1"
      },
      conversation = new Conversation()
      {
          isGroup = false,
          id = "8a684db8",
          name = "Conv1"
      },
      recipient =   new Recipient()
      {
          id = "56800324",
          name = "Bot1"
      },
      text = "ping",
      attachments = new object[0],
      entities = new object[0]
    };

    var content = new StringContent(jsonObject.ToString(), Encoding.UTF8, "application/json");
    var result = client.PostAsync("http://emiko.azurewebsites.net/api/messages", content).Result;
    result.ToString();          

But I get an authorization error: StatusCode: 401, ReasonPhrase: 'Unauthorized', Version: 1.1, Content: System.Net.Http.StreamContent...

How can I login correctly on the Bot and send a message on its Url (http://emiko.azurewebsites.net/api/messages)


回答1:


As mentioned in the official document about Always On:

By default, web apps are unloaded if they are idle for some period of time. This lets the system conserve resources. In Basic or Standard mode, you can enable Always On to keep the app loaded all the time. If your app runs continuous web jobs, you should enable Always On, or the web jobs may not run reliably.

To activate the option ' Always on ', it is necessary to pass on a paying offer. As I am still there dev, I cannot pass on this offer.

Based on your scenario, I assumed that you could periodically send requests to make sure your site is alive, here are some tutorials you could refer to them (tutorial1 and tutorial2).



来源:https://stackoverflow.com/questions/42508817/bot-responses-with-lag-after-certain-time-of-non-use

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!