Reduce repeated data handler calls by the operations grouping.
Project description
Python Pipeline Algorithmic Optimizer
Reduce repeated data handler calls by the operations grouping.
Do I need the ppao?
Even if you cache your heavy handlers in the NoSQL database, you can still reduce the number of queries to the database with ppao.
What is the idea?
Often, multiple single-threaded workers are used to handle queues of pipelines:
The algorithm allows you to increase the amount of data processed by the handler at a time by grouping operations in the pipelines in such a way that the sequence of the pipelines is not broken.
Benefits:
- You can significantly reduce the number of calls to data handlers or requests to the database to retrieve a cached handler.
- You can group requests to a third-party API to send more data in a single transaction, if that's more advantageous in your case.
Limitations:
- Algorithm is only suitable for the architecture described in the pictures above.
- The maximum number of operations in the pipelines must be limited and all pipelines must be the same length. If there are fewer operations, zeros are placed in the empty space.
- You should be ready to add the numpy dependency to your project.
- Not all pipelines may be suitable for using this algorithm. The "Grouper" is responsible for checking this. If a pipeline cannot be grouped with others, it will have to wait for new pipelines with which it can form a group to successfully solve the problem. If you don't want to wait, execute the pipeline without ppao. The decision is up to you.
Explanation of the algorithm.
Components:
Dependencies:
- numpy
- python >= 3.10
Installation:
With pip:
pip install ppao
Git:
git clone https://github.com/borontov/ppao.git
poetry:
poetry install
conda-lock:
conda-lock install --micromamba -n ppao_dev_env conda-lock.yml
Getting Started
Example:
from ppao import (
Grouper,
PipelineMatrixSolver,
settings as ppao_settings,
)
import numpy as np
settings_ = ppao_settings.Settings(
group_size_limit=4,
pipeline_size_limit=4,
common_ops_percent_bound=0.85,
)
pipelines = np.array(
[
[1, 3, 1, 2],
[1, 1, 1, 2],
[3, 2, 1, 1],
[1, 2, 2, 1],
],
)
grouper = Grouper(settings_=settings_)
grouper.add(pipelines=pipelines)
source_matrix = grouper.pop()
solver = PipelineMatrixSolver(
source_matrix=source_matrix,
settings_=settings_,
)
solution = solver.solve()
print(solution)
# output:
# [
# ExecutionUnit(operation=1, pipelines=array([0, 2, 0, 1], dtype=uint16)),
# ExecutionUnit(operation=3, pipelines=array([2, 3], dtype=uint16)),
# ExecutionUnit(operation=1, pipelines=array([0, 2], dtype=uint16)),
# ExecutionUnit(operation=2, pipelines=array([1, 3, 0, 1, 2], dtype=uint16)),
# ExecutionUnit(operation=1, pipelines=array([3, 1, 3], dtype=uint16))
# ]
Solution usage:
for execution_unit in solution:
handler = get_handler(execution_unit.operation)
for pipeline_id in execution_unit.pipelines:
pipeline_data = get_pipeline_data(pipeline_id)
handler(pipeline_data)
Roadmap
- Add debug logging
- Deduplicate equal shift combinations like (-1, -1, 0, 0) & (0, 0, 1, 1)
See the open issues for a full list of proposed features (and known issues).
Contributing
Contributions are welcome.
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature) - Prepare your feature with shell commands:
- make format
- make check
- make test
- Commit your Changes (
git commit -m 'Add some AmazingFeature') - Push to the Branch (
git push origin feature/AmazingFeature) - Open a Pull Request
License
Distributed under the MIT License. See LICENSE.txt for more information.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file ppao-1.0.tar.gz.
File metadata
- Download URL: ppao-1.0.tar.gz
- Upload date:
- Size: 14.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.5.1 CPython/3.10.11 Linux/6.1.29
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
26d57430ea686307556dba7eb3accd0076be2320bbb45298c9a0f185e7535203
|
|
| MD5 |
8bbac634759dc8050674275f4a4f8f4c
|
|
| BLAKE2b-256 |
3f44571254bfa1c4a9206c6b56c7c86f0fe2e6b3c306ef0ae2d8dadde2f3aa25
|
File details
Details for the file ppao-1.0-py3-none-any.whl.
File metadata
- Download URL: ppao-1.0-py3-none-any.whl
- Upload date:
- Size: 14.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.5.1 CPython/3.10.11 Linux/6.1.29
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f79e4007f6b465cc0446c4b523b52aa424989e8ccf40a64cd4af834c457f50f9
|
|
| MD5 |
c9966fdda8bad7e6d1d7d6255003d402
|
|
| BLAKE2b-256 |
8129e97c1564719bf400aaf8c9c1e113c7d9162adc4ad4af511e69c168d59acd
|