Skip to content

Logging causes excessive lock contention #2276

@oakaigh

Description

@oakaigh

The default logging makes pyav almost unusable for thread-parallelized workloads. Below is a trace obtained by py-spy:

$ py-spy top --pid 2875341 --native --full-filenames
  %Own   %Total  OwnTime  TotalTime  Function (filename)                                                                                       
 96.00%  96.00%    9.11s     9.11s   __futex_abstimed_wait_common (/usr/lib64/libc.so.6)
 88.00%  88.00%    8.06s     8.06s   __lll_lock_wait (/usr/lib64/libc.so.6)
 40.00%  40.00%    3.52s     3.52s   pthread_cond_signal@@GLIBC_2.3.2 (/usr/lib64/libc.so.6)
 37.00%  37.00%    2.27s     2.27s   __lll_lock_wake (/usr/lib64/libc.so.6)
  4.00%  31.00%   0.640s     2.89s   pthread_mutex_lock@@GLIBC_2.2.5 (/usr/lib64/libc.so.6)
  3.00%  40.00%   0.490s     2.76s   __pthread_mutex_unlock_usercnt (/usr/lib64/libc.so.6)
  5.00% 266.00%   0.310s    24.40s   logging_log_callback (/project/src/av/logging.c)

The issue can be solved by actively disabling pyav's logging through av.logging.set_level(None).
However, since pyav by default hooks itself into python's logging system when av.logging is first imported,
there is no way to enforce this behavior if other modules are also using it (unless we import before everyone else, which isn't possible for library code).

I therefore propose two fixes:

  1. Make logging async and lock free.
  2. Do not hook into python's logging system unless explicitly asked.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions