modal-labs / modal-client

Python client library for Modal
https://modal.com/docs
Apache License 2.0
271 stars 35 forks source link

[MOD-3194] python module import tracing #1938

Closed danielnorberg closed 3 months ago

mwaskom commented 3 months ago

Is there any reason not to put this into the main package as modal._telemetry (or wherever)? We're trying to consolidate everything in the client repo, as the "modern" way of distributing Python doesn't support multiple packages in one release.

danielnorberg commented 3 months ago

@mwaskom gotcha, let me try moving it in to the main package

danielnorberg commented 3 months ago

Done, ptal again.

danielnorberg commented 3 months ago

There is a noticeable performance impact, seemingly mostly due to the call to Queue.put_nowait. Could do some PyO3, but seems overkill for now as this telemetry will only run when task tracing is enabled.

To get a ballpark sense of the impact, with these below imports:

import kubernetes
import torch
import django

On a linux devbox running python 3.11, with tracing disabled:

imports took 1.5s

With tracing enabled:

imports took 1.8s

This is for ~3700 modules being imported in total.