Giter Site home page Giter Site logo

async-batcher's Introduction

Async Batcher

This project provides a Python library to batch the asynchronous requests and handle them in batches.

How to use

To use the library, you need to install the package in your environment. You can install the package using pip:

pip install async-batcher

Then, you can create a new AsyncBatcher class by implementing the process_batch method:

from async_batcher.batcher import AsyncBatcher

class MyAsyncBatcher(AsyncBatcher):
    async def process_batch(self, batch):
        # Process the batch
        print(batch)

# Create a new instance of the `MyAsyncBatcher` class
async_batcher = MyAsyncBatcher(max_batch_size=20)
async_batcher.start()

Benchmark

The benchmark is available in the BENCHMARK.md file.

Use cases

The AsyncBatcher library can be used in any application that needs to handle asynchronous requests in batches, such as:

  • Serving machine learning models that optimize the batch processing (e.g. TensorFlow, PyTorch, Scikit-learn, etc.)
  • Storing multiple records in a database in a single query to optimize the I/O operations (or to reduce the cost of the database operations, e.g. AWS DynamoDB)
  • Sending multiple messages in a single request to optimize the network operations (or to reduce the cost of the network operations, e.g. Kafka, RabbitMQ, AWS SQS, AWS SNS, etc.)

async-batcher's People

Contributors

hussein-awala avatar nmehraein avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

async-batcher's Issues

Implement an AsyncBatcher for MongoDB

MongoDB supports bulkWrite operation that allows batching different types of write operations (insertOne, updateOne, updateMany, deleteOne, deleteMany, and replaceOne).

To interact with MongoDB asynchronously, we can use Motor package, that supports the ordered bulk write operation which we need to process the batch and return the result.

Implement an AsyncBatcher for Pinecone

Pinecone is a vector database used in ML and AI projects. Pinecone supports inserting, updating, upserting, and even querying vectors in batches, which according to Pinecone's official site "significantly reduces the time it takes to process data."

We can use the official Python client to achieve this.

Implement an AsyncBatcher for Apache Kafka

Producing Kafka messages in batches helps optimize network utilization and improve overall throughput.

aiokafka is the most used package to interact with Kafka asynchronously from Python, this package doesn't support an implicit batching mechanism. Instead, the user can create the batches explicitly and send them to Kafka.

Here is an example of how to produce messages in batches using aiokafka, which would be great to support in our package.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.