Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a simple thread pool #1746

Merged
merged 2 commits into from
Jan 4, 2025
Merged

Add a simple thread pool #1746

merged 2 commits into from
Jan 4, 2025

Conversation

neo1973
Copy link
Member

@neo1973 neo1973 commented Dec 30, 2024

Description

Implement a simple thread pool so threads can be reused instead of recreated.

Motivation and context

inputstream.adaptive creates a lot of threads though std::async or by instantiating std::thread directly. E.g. watching this stream I measured about 90 threads being created and destroyed per second (very inaccurate measure using a stopwatch and GDB debug output):

#KODIPROP:mimetype=application/dash+xml
#KODIPROP:inputstream=inputstream.adaptive
#KODIPROP:inputstream.adaptive.manifest_type=mpd
#A new period every 3 min (20 times/hour)
#no segment updates needs inserting
https://livesim.dashif.org/livesim/periods_20/testpic_2s/Manifest.mpd

Creating threads is a non trivial task and reusing threads instead of recreating them improves efficiency.

How has this been tested?

Tested with the above stream and https://github.com/anxdpanic/plugin.video.youtube/. I confirmed in GDB on Linux that the thread pool grows to a size of only two and then no new threads are created.

Types of change

  • Bug fix (non-breaking change which fixes an issue)
  • Clean up (non-breaking change which removes non-working, unmaintained functionality)
  • Improvement (non-breaking change which improves existing functionality)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that will cause existing functionality to change)
  • Cosmetic change (non-breaking change that doesn't touch code)
  • None of the above (please explain below)

Checklist:

  • I have read the Contributing document
  • My code follows the Code Guidelines of this project
  • My change requires a change to the Wiki documentation
  • I have updated the documentation accordingly

@neo1973 neo1973 added Type: Improvement non-breaking change which improves existing functionality v22 Piers labels Dec 30, 2024
@CastagnaIT
Copy link
Collaborator

interesting alternative solution, although the ReadSampleAsync "functionality" should be completely rewritten in a future can in the meantime be an improvement
i will take a look on next days

#include <vector>

#pragma once

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please add appropriate namespaces such as the others utils files
at least the "utils"

namespace UTILS
{

src/test/CMakeLists.txt Outdated Show resolved Hide resolved
Copy link
Collaborator

@CastagnaIT CastagnaIT left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tested on windows and android
not found problems

@CastagnaIT CastagnaIT merged commit 4b49c87 into xbmc:Piers Jan 4, 2025
7 of 10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Improvement non-breaking change which improves existing functionality v22 Piers
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants