Azure 函数中的 OutOfMemoryException

OutOfMemoryException In Azure Function

我正在使用下面的代码从工作日提取数据并将它们存储在用户列表中以供处理:

  Workday_Common_HeaderType header = new Workday_Common_HeaderType();
            //Fill the Workday header at your wish (omitted for code clarity)

            header.Include_Reference_Descriptors_In_ResponseSpecified = true;
            header.Include_Reference_Descriptors_In_Response = true;
            //Setting up request criteria to use Country
            var request = new Get_Workers_RequestType { version = "v33.2" };
            gremlinQueries.Clear();
            //Fill the Workday request at your wish (omitted for code clarity)
            request.Response_Filter = new Response_FilterType();
            request.Response_Group = new Worker_Response_GroupType();
            request.Response_Group.Include_Management_Chain_Data = true;
            request.Response_Group.Include_Management_Chain_DataSpecified = true;
            request.Response_Group.Include_Multiple_Managers_in_Management_Chain_DataSpecified = true;
            request.Response_Group.Include_Multiple_Managers_in_Management_Chain_Data = true;
            request.Response_Group.Include_Personal_InformationSpecified = true;
            request.Response_Group.Include_Personal_Information = true;
            request.Response_Group.Include_Employment_InformationSpecified = true;
            request.Response_Group.Include_Employment_Information = true;
            request.Response_Group.Include_RolesSpecified = true;
            //request.Response_Group.Include_Development_ItemsSpecified = true;
            //request.Response_Group.Include_Development_Items = true;
            request.Response_Group.Include_RolesSpecified = true;
            request.Response_Group.Include_Roles = true;
            request.Response_Group.Include_OrganizationsSpecified = true;
            request.Response_Group.Include_Organizations = true;
            request.Response_Group.Include_Employment_InformationSpecified = true;

            request.Response_Group.Include_Employment_Information = true;
           int totalResults = 0;
            for (int i = 1; i < totalPages; i++)
            {

                request.Response_Filter.Page = i;
                request.Response_Filter.Count = test ? 14 : 500; //500 page count per request
                //   request.Response_Group.Include_Management_Chain_Data
                request.Response_Filter.CountSpecified = true;
                request.Response_Filter.PageSpecified = true;
                //Invoke HR getworker api via Proxy 

                var workers = proxy.Get_Workers(header, request);
                if (test != true)
                    totalPages = (int)workers.Response_Results.Total_Pages + 1;
                totalResults = (int)workers.Response_Results.Total_Results;
                if (workers.Response_Data == null)
                {
                    break;
                }

                foreach (var worker in workers.Response_Data)
                {

                    User user = new User();
                    user.StillHired = worker.Worker_Data.Employment_Data.Worker_Status_Data.Active;
                    user.HireDate = worker.Worker_Data.Employment_Data.Worker_Status_Data.Hire_Date;

现在我在本地 运行 它没有问题,但是当我在 Azure 中部署它时,一个小时后我收到错误内存不足异常,而且功能状态始终是错误。 函数 运行ning 使用 AppServicePlan 7GB 内存。 异常:

执行函数时出现异常:ExportWorkday System.OutOfMemoryException 在 Human_ResourcesPort.Get_Workers

您可以在 Azure 门户->您的应用服务->指标中查看内存利用率。

如果内存耗尽,您可以扩展服务计划或将功能应用程序移动到其他托管计划来解决此问题。

如果问题依然存在,可以在本地运行函数应用,监控内存占用,看看是不是代码本身的问题。