GithubHelp home page GithubHelp logo

pingpong's Introduction

Ping Pong Service PoC with Nameko, Kafka and Flask

Architecture

Services

  • API (flask):
    • Make asynchronous calls to nameko services ping and pong.
    • Endpoints are synchronous. TODO: They should be asynchronous and return a 202.
  • Ping (nameko service):
    • exposes a RPC endpoint to send messages to pong topic.
    • consumes messages from ping topic
  • Pong (nameko service):
    • exposes a RPC endpoint to send messages to pong topic.
    • consumes messages from pong topic and sends another message to ping topic

Brokers

  • Zookeeper: Required by kafka
  • Kafka: Messages
  • Rabbit: Async communication between services

Run with docker compose

Run brokers with docker-compose up --build broker zookeeper rabbit

In a separate terminal, run the services:

Run docker-compose up --build ping pong api

Test

Create one example of test for ping service. Run pytest

Benchmarking

Very simple metrics:

  • Producers:

    To send messages from ping to pong: curl localhost:8000/ping/<num_messages>/<size>. Then pong will generate a response to ping.

    To send messages from pong to ping: curl localhost:8000/pong/<num_messages>/<size> Ping will not generate a response to pong to break the loop

    Endpoint response returns the metrics e.g:

        {
            "num_messages": 100,
            "size": 100,
            "total time": 3.14684796333313,
            "byte rate (MB/s)": 0.0031777830122457,
            "message rate (msg/s)": 31.777830122457
        }
    
  • Consumers:

    We have to look at the logs produced by the consumer. There are better ways to track this with Confluent:

    Stats are computed in batches of 100 messages. Batch size can be modified in docker compose: CONSUMER_METRIC_BATCH: "100"

    Run curl localhost:8000/ping/<num_messages>/<size> to see the performance of the consumers in ping and pong services

    Run curl localhost:8000/pong/<num_messages>/<size> to see only the performance of the consumer in ping when sending messages from pong.

Kafka metrics are complicated. Next I list the most important metrics to track in production:

Key metrics:

  • Producer:

    • Rate
    • Transmission failure
  • Brokers

    • Load skew
    • Capacity
  • Topics

    • Load skew. Some topics can be overloaded
  • Consumers

    • Consumer rate

Local development env

Developement enviroment can be created with pipenv install

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.