Azure函数-nodejs和dot net core 2.2的内存消耗一直在增长,直到被回收为止

问题描述 投票:0回答:1

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

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

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

而且,如果您知道如何为应用程序服务中托管的特定azure函数转储内存,将很有帮助。

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 });
            }
        }
    }
}
c# node.js azure-functions asp.net-core-2.2 csx
1个回答
0
投票
使用ProcDump.exe手动收集内存转储
© www.soinside.com 2019 - 2024. All rights reserved.