Git Product home page Git Product logo

microbatch's Introduction

Micro-batching Mock Service

Overview

This service demonstrates a micro-batching library, which processes tasks in batches to improve throughput. The library allows for submitting jobs, processing them in batches, and retrieving results. It is configurable for batch size and interval, and provides a shutdown method to ensure all jobs are processed before the service exits.

Running the Service within a Docker Container

  1. Run Docker Container:

    docker run --rm -it -v ./:/app -p 8080:8080 golang:1.18-alpine /bin/sh
  2. Navigate to the Application Directory:

    cd /app
  3. Install GCC and Other Necessary Build Tools:

    apk update && apk add --no-cache gcc musl-dev
  4. Build the Service:

    go build -o microbatch-service main.go
  5. Run the Service:

    ./microbatch-service
  6. Send Requests:

    • Submit a job:

      curl -X POST -H "Content-Type: application/json" -d '{"data":"sample data","value":123}' http://localhost:8080/submit
    • Shutdown the service:

      curl -X POST http://localhost:8080/shutdown
    • Get the result of a job:

      curl -X POST http://localhost:8080/result?id=3
  7. Run Unit Tests:

    go test ./microbatch

Running the Docker Image

  1. Build the Docker Image:

    docker build -t microbatch-service .
  2. Run the Docker Container:

    docker run -p 8080:8080 -e BATCH_SIZE=5 -e BATCH_INTERVAL=10 microbatch-service

Configuration

  • BATCH_SIZE: The number of jobs to accumulate before processing a batch.
  • BATCH_INTERVAL: The maximum time interval (in seconds) to wait before processing a batch.

Example Usage

Submit a job to the service:

curl -X POST -H "Content-Type: application/json" -d '{"data":"example data","value":456}' http://localhost:8080/submit

Shutdown the service:

curl -X POST http://localhost:8080/shutdown

Retrieve the result of a job:

curl -X GET "http://localhost:8080/result?id=1"

Development and Testing

Ensure all dependencies are installed and the development environment is set up. Run the unit tests to verify the functionality of the micro-batching library.

go test ./microbatch

microbatch's People

Contributors

martinjlee avatar

Watchers

 avatar

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.