Skip to content

Timeout when exporting chart based on large dataset #392

@oscarsommerer

Description

@oscarsommerer

Description

Calling Chart.toBase64PNGString (or any other export function) on a chart backed by a large enough dataset leads to a PuppeteerSharp timeout.

I'm trying to render a PointDensity chart with about one million items for the x/y values in a .NET interactive session (vscode polyglot notebook). Without exporting, this is done in a few seconds, but when trying to export the chart I get a timeout exception from PuppeteerSharp.

Repro steps

Run the F# following snippet

open Plotly.NET
open Plotly.NET.ImageExport

let x = [ for i in 0 .. 1000000 -> System.Random.Shared.Next() ]
let y = [ for i in 0 .. 1000000 -> System.Random.Shared.Next() ]

Chart.PointDensity(x = x, y = y)
|> Chart.toBase64PNGString (Width = 300, Height = 300)

Expected behavior

The export should return a base64 PNG string, even if generating the image takes longer than 30 seconds.

I'm wondering if it would be feasible to supply a custom timeout?

Actual behavior

The function throws a TimeoutException after about 30 seconds.

Error: System.AggregateException: One or more errors occurred. (One or more errors occurred. (Timeout of 30000 ms exceeded))
---> System.AggregateException: One or more errors occurred. (Timeout of 30000 ms exceeded)
---> System.TimeoutException: Timeout of 30000 ms exceeded
at PuppeteerSharp.Helpers.TaskHelper.<>c__DisplayClass2_0.<WithTimeout>b__0() in C:\projects\puppeteer-sharp\lib\PuppeteerSharp\Helpers\TaskHelper.cs:line 48
at PuppeteerSharp.Helpers.TaskHelper.WithTimeout(Task task, Func`1 timeoutAction, TimeSpan timeout, CancellationToken cancellationToken) in C:\projects\puppeteer-sharp\lib\PuppeteerSharp\Helpers\TaskHelper.cs:line 93
at PuppeteerSharp.DOMWorld.SetContentAsync(String html, NavigationOptions options) in C:\projects\puppeteer-sharp\lib\PuppeteerSharp\DOMWorld.cs:line 253
--- End of inner exception stack trace ---
at <StartupCode$Plotly-NET-ImageExport>[email protected]()
at <StartupCode$Plotly-NET-ImageExport>.$PuppeteerSharpRenderer.Plotly-NET-ImageExport-IGenericChartRenderer-RenderPNGAsync@143.MoveNext()
--- End of inner exception stack trace ---
at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
at System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification)
at [email protected](Task`1 t)
at Plotly.NET.ImageExport.AsyncHelper.runSync[a,b](FSharpFunc`2 job, a input)
at Plotly.NET.ImageExport.AsyncHelper.taskSync[a](Task`1 task)
at Plotly.NET.ImageExport.ChartExtensions.ToBase64PNGString@134.Invoke(GenericChart gChart)
at <StartupCode$FSI_0012>.$FSI_0012.main@()
at System.RuntimeMethodHandle.InvokeMethod(Object target, Void** arguments, Signature sig, Boolean isConstructor)
at System.Reflection.MethodInvoker.Invoke(Object obj, IntPtr* args, BindingFlags invokeAttr)

Known workarounds

Rendering the chart without the static export function and using the export button works as expected.

Reducing the number of items to about one hundred thousand also seems to let PuppeteerSharp render the image fast enough, so as to not run into the timeout

Related information

  • OS: Fedora 38
  • Plotly.NET.ImageExport, 4.0.0
  • Plotly.NET.Interactive, 4.1.0
  • .NET Runtime 7.0.302
  • Running a fairly old Intel® Core™ i7-3770 CPU

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions