Git Product home page Git Product logo

Comments (5)

h2non avatar h2non commented on June 21, 2024

Discovery process and requests are indepent workflows across requests. This should not be possible. It's true that discovery request can happen multiple times if the first discovery process was not satisfied. This is something that can be changed using a synchronization mechanism.

from resilient.js.

h2non avatar h2non commented on June 21, 2024

If you provide more details, such as the type of error you're getting, and some code to reproduce it, I might be able to assist you better.

from resilient.js.

jangot avatar jangot commented on June 21, 2024

This is my example

const resilientMiddlewareEureka = require('./resilient-middleware-eureka');
const Resilient = require('resilient');
let http = require('http');


// Resilient initialisations
const options = {
    balancer: {
        random: true,
        roundRobin: false
    },
    discovery: {
        servers: ['http://localhost:7777/eureka/v1/apps']
    },
    service: {}
};

let client = new Resilient(options);

client.use(resilientMiddlewareEureka('PROJECTS-API'));


// Run requests
const ITERATIONS_COUNT = 10;
let success = 0;
let promise = Promise.resolve(0);

// send 10 portions of requests
for (let i = 0; i <= ITERATIONS_COUNT; i++) {
    promise = promise
        .then((successCount) => {
            console.log(`success ${i}`);
            success += successCount;

            // send one portion (100 requests parallel)
            return makePackRequests(10);
        });
}

promise
    .then((successCount) => {
        success += successCount;
        console.log(`SUCCESS COUNT: ${success}`);
    })
    .catch((e) => {
        console.log(`error:`, e);
    });

function makePackRequests(count) {
    let promises = [];
    let successCount = 0;
    for (let i = 0; i < count; i++) {
        let promise = client.get('/projects')
            .then(() => {
                successCount++;
            })
            .catch((e) => {
                console.log(`ERROR`);
                console.log(e.message);
            });
        promises.push(promise);
    }

    return Promise
        .all(promises)
        .then(() => {
            return successCount;
        });
}

This is my result

success 0
OIUT
ERROR
Discovery server response is invalid or empty
ERROR
Discovery server response is invalid or empty
ERROR
Discovery server response is invalid or empty
ERROR
Discovery server response is invalid or empty
ERROR
Discovery server response is invalid or empty
ERROR
Discovery server response is invalid or empty
ERROR
Discovery server response is invalid or empty
ERROR
Discovery server response is invalid or empty
ERROR
Discovery server response is invalid or empty
success 1
success 2
success 3
success 4
success 5
success 6
success 7
success 8
success 9
success 10
SUCCESS COUNT: 101

And, how can I use a synchronization mechanism?
Need I set other http client?

from resilient.js.

h2non avatar h2non commented on June 21, 2024

You can implement the synchronization inside your Eureka middleware by keeping a global state of the discovery requests. E.g: during the first discovery request call within your middleware logic, you create a promise that would be resolved only when you get the response from Eureka. Subsequent concurrent discovery calls would check if that promise exists and would subscribe to it instead of performing the discovery process again.
That being said, I'm not fully sure where the problem origin actually is, but I suspect it's related to the custom middleware. As far as I know resilient.js behavior is consistent.

from resilient.js.

jangot avatar jangot commented on June 21, 2024

I wanted to use your solution but it makes overhead for requests. And I think that several equal requests is bad approach. I made small fix for my team and I hope it will make the lib better.
#144

from resilient.js.

Related Issues (20)

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.