Search code examples
c#azure-functionsworkday-api

OutOfMemoryException In Azure Function


I am pulling data from workday using code below and storing them in User List for processing :

  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;

now locally I run it with no issues but when I deploy it in Azure I receive error outofmemory exception after an hour also the function status is always error. Function is running using an AppServicePlan 7GB memory. Exception :

Exception while executing function: ExportWorkday System.OutOfMemoryException at Human_ResourcesPort.Get_Workers


Solution

  • You can view the memory utilization in Azure portal->your app service-> Metrics.

    enter image description here

    If the memory is exhausted, you can scale up the service plan or move the function app to another hosting plan to solve this issue.

    If the issue still exist, you can run the function app locally and monitor the memory usage to see if there are some issues of the code itself.