Coder Social home page Coder Social logo

goodbye's Introduction

GoodBye demo

This project demonstrates the motivations to use a circuit-breaker for REST endpoints as well as Vert.x's capability to offload "blocking" tasks to background threads. Keeping the foreground event-loop always responsive.

It's composed by two parts

  • server - REST endpoint with two resources (/api/goodbye and /api/nap). There are three different implementations for the Server (WildFly Swarm, Spring Boot, Vert.x).
  • client - Java client that consumes http://localhost:8080/api/nap

Server execution

The /api/nap resource blocks for several seconds as it is calculating Pi. It's used to demonstrate the behaviour of REST producer/consumer when the resource is taking too much time to respond.

    $ cd server/<implementation>
    
    # For WildFly Swarm
    $ mvn clean compile wildfly-swarm:run
    
    # For Spring Boot
    $ mvn clean compile spring-boot:run

    # For Vert.x
    $ vertx run --instances 1 -Dvertx.options.workerPoolSize=100 src/main/java/com/redhat/developers/msa/goodbye/ServerVerticle.java
    
    Note: Vert.x also runs as a fat jar, in this case we just wanted to "fix" the thread pool to 100 like it was for Spring Boot

The server will accept requests on http://localhost:8080/api/goodbye and http://localhost:8080/api/nap.

Client execution

The client will trigger 210 Threads against the /api/nap endpoint running on the server.

    cd client/
    vim src/main/java/com/redhat/developers/msa/goodbye/client/Main.java
    # Uncomment the desired Thread implementation
    # Save the file and exit
    
    mvn compile exec:java

There are 3 different Threads implementations:

  • ApacheClient - It uses Apache HTTPClient to connect to the /api/nap endpoint running on server.
  • TimeoutApacheClient - Apache HTTPClient is now configured to have 1 second of timeout.
  • HystrixClient - It uses Feign/Hystrix. Hystrix is a circuit-break implementation from NetflixOSS.

When using ApacheClient, the server and client threads go busy and the server stops responding on /api/goodbye. This is very similar to a denial-of-service attack.

With the TimeoutApacheClient, the client threads fail fast now, but the server still having all threads in the thread-pool on WAIT state.

Using HystrixClient, after the 10th request, the circuit opens. The client fails fast and the server is just hit by 10 requests.

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.