0

我有一个简单的 http 触发 azure 函数,它从 azure sql 数据库中检索标量值并将其作为 json 返回,该函数使用 azure app 服务计划托管,我尝试过“dot net core 2.2 app package”和“nodejs”两者其中的一些使内存消耗随着时间的推移而不断增长,直到内存达到 90% 或 100% 以上,然后 GC 开始工作或应用程序被回收我不知道其中发生了哪些,但在那之后内存恢复正常并且再次开始生长。奇怪的是,我尝试了与 csharp 脚本相同的 dot net core 2.2 代码,在这种情况下,它可以正常工作,并且内存从未超过应有的增长。

任何人都可以解释点网核心应用程序和 CSX 内存消耗之间的区别吗?

在所有情况下,我都使用 x64 环境

如果您知道如何转储应用程序服务中托管的特定天蓝色函数的内存,这将很有帮助。

using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.Http;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
using System;
using System.Data.SqlClient;
using System.Threading.Tasks;

namespace MyNamespace
{
    public static class GetNumber
    {
        [FunctionName("GetNumber")]
        public static async Task<IActionResult> Run([HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = null)] HttpRequest req, ILogger log, ExecutionContext context)
        {
            log.LogInformation("C# HTTP trigger function processed a request.");

            try
            {
                string code = req.Query["code"];
                if (code.Equals("123") == false)
                {
                    return new BadRequestObjectResult("Invalid API Call!");
                }
                if (int.TryParse(req.Query["id"], out int id) == false)
                {
                    return new BadRequestObjectResult("Invalid Id!");
                }

                var config = new ConfigurationBuilder()
                    .SetBasePath(context.FunctionAppDirectory)
                    .AddJsonFile("local.settings.json", optional: true, reloadOnChange: true)
                    .AddEnvironmentVariables()
                    .Build();
                var connString = config.GetSection("ConnectionStrings").GetSection("MyDBConnectionString").Value;
                int number = 0;
                using (var sqlConnection = new SqlConnection(connString))
                {
                    using (var sqlCommand = sqlConnection.CreateCommand())
                    {
                        sqlCommand.CommandType = System.Data.CommandType.StoredProcedure;
                        sqlCommand.CommandText = "GetNumber";
                        sqlCommand.Parameters.AddWithValue("Id", id);
                        sqlConnection.Open();
                        number = (int)await sqlCommand.ExecuteScalarAsync();
                        sqlCommand.Dispose();
                        sqlConnection.Close();
                    }
                }
                var result = new ContentResult();
                result.Content = "{\"number\":" + number + "}";
                result.ContentType = "application/json";
                result.StatusCode = StatusCodes.Status200OK;
                return result;
            }
            catch (Exception ex)
            {
                log.LogError(ex.Message, ex);
                return (ActionResult)new OkObjectResult(new { number = 0 });
            }
        }
    }
}
4

1 回答 1

0

使用 ProcDump.exe 手动收集内存转储

有关更多信息,请关注博客:https ://blogs.msdn.microsoft.com/kaushal/2017/05/04/azure-app-service-manually-collect-memory-dumps/

于 2019-09-26T16:27:08.517 回答