Suspended Chrome processes resulting in slow performance.



  • Hey guys,

    We're having problems with suspended chrome processes which affects the time to generate a PDF document from about 2 seconds per PDF to more than 20 seconds. We are generating about 6,500 documents so this blows out the time to process significantly. I am kicking off the process in Startup.cs using:

    services.AddJsReport(new LocalReporting()
        .UseBinary(JsReportBinary.GetBinary())
        .KillRunningJsReportProcesses()
        .AsUtility()
        .Create());
    

    And I have a PdfGenerator class which has the IJsReportMVCService passed in.

    internal class PdfGenerator
    {
        private readonly IJsReportMVCService _jsReportMvcService;
        private readonly HttpContext _httpContext;
        private readonly RouteData _routeData;
        private readonly HttpRequest _request;
    
        public PdfGenerator(IJsReportMVCService jsReportMvcService, HttpContext httpContext, RouteData routeData, HttpRequest request)
        {
            _jsReportMvcService = jsReportMvcService;
            _httpContext = httpContext;
            _routeData = routeData;
            _request = request;
        }
    
        internal async Task<Stream> RenderAsync(
            string content, 
            Orientation orientation, 
            string header, 
            string footer, 
            decimal? marginTopCm = null, 
            decimal? marginBottomCm = null)
        {
            var displayHeaderFooter = !string.IsNullOrEmpty(header) || !string.IsNullOrEmpty(footer);
            
            var report = await _jsReportMvcService.RenderAsync(new RenderRequest
            {
                Template = new Template
                {
                    Recipe = Recipe.ChromePdf,
                    Engine = Engine.None,
                    Content = content,
    
                    Chrome = new Chrome
                    {
                        HeaderTemplate = header,
                        FooterTemplate = footer,
                        DisplayHeaderFooter = displayHeaderFooter,
                        Height = "29.7cm",
                        Width = "21cm",
                        MarginTop = displayHeaderFooter 
                            ? marginTopCm.HasValue 
                                ? $"{marginTopCm.ToString()}cm" : "4cm" 
                            : "1cm",
                        MarginLeft = "1cm",
                        MarginRight = "1cm",
                        MarginBottom = displayHeaderFooter 
                            ? marginBottomCm.HasValue 
                                ? $"{marginBottomCm.ToString()}cm" : "2cm" 
                            : "1cm",
                        Landscape = orientation == Orientation.Landscape,
                        MediaType = MediaType.Print
                    }
                }
            });
    
            return report.Content;
        }
    }
    

    However when I set up locally I am unable to reproduce this issue, it's only on our prod server. The dotnet application is running using IIS and the IIS version is 10.0.14393.0 running on windows 10 of the same version. It seems to get slower over time meaning it's likely that the number of suspended processes increases over time. Any ideas on this?



  • Sorry for the delayed answer. I have no clue why this is sometimes happening. I wasn't able to replicate it. I see some people complain about it even with a standalone chrome.

    Please try to add this to your code, it should tell jsreport to reuse chrome instances, so it should prevent the suspended orphans.

    Environment.SetEnvironmentVariable("chrome_strategy", "chrome-pool");
    Environment.SetEnvironmentVariable("chrome_numberOfWorkers", "2");
    
    var rs = new LocalReporting()...
    


  • Perfect! I tested against 6,500 documents with no orphaned processes. Is it worth considering setting these environment variables as part of the jsreport package? I feel that setting these environment variables should be the default behavior. FYI here's my final implementation:

    // Add JS Report for PDF generation.
    Environment.SetEnvironmentVariable("chrome_strategy", "chrome-pool");
    Environment.SetEnvironmentVariable("chrome_numberOfWorkers", "2");
    services.AddJsReport(new LocalReporting()
        .UseBinary(JsReportBinary.GetBinary())
        .KillRunningJsReportProcesses()
        .AsUtility()
        .Create());
    


  • Yes, thank you for the confirmation.

    I included the note to the v3 plan to consider adding chrome-pool as default.


Log in to reply
 

Looks like your connection to jsreport forum was lost, please wait while we try to reconnect.