New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implementing ApiCall class #4
Comments
Yup, this is exactly how it works.
No,
When a node is marked as unhealthy, |
One more question suppose we have three nodes |
The nearest node is a 4th node The logic is that, if |
@mafreud I'm looking for some suggestions: I've gone through how the JS and Python clients are making requests. I'm thinking rather than implementing everything ourselves, we could use the I'm thinking something like this class ApiCall {
final Configuration config;
Map<Node, http.BaseClient> _nodes;
int _nodeIndex = 0;
bool _usingNearestNode;
http.Client _nearestClient;
ApiCall(this.config) {
_nodes = Map.fromIterable(
config.nodes,
key: (node) => node,
value: (node) => null, // Lazily initialize the clients.
);
_usingNearestNode = config.nearestNode != null;
if (config.nearestNode != null) {
_nearestClient = http.Client();
}
}
} but that'll become cumbersome so maybe having a Edit: Also then the class ApiCall {
// ...
Future<T> post (...) {
_nodes[_nodeIndex].client.post(...);
}
} |
@happy-san Depending packages makes projects hard for maintaining, so I agree with you. 😄 |
Oh okay so we don't want to depend on external packages at all? I was saying
regarding
Also I do agree with you that depending on external packages increases the technical debt but I believe since it's a package developed by the dart team itself we can depend on it. What's your take? |
Right, it's okay to depend http package. it's well maintained by dart team. |
What I wanted to say is depending unnecessary packages (or too many packages) is not suited for this project. As you probably know! |
I think this'll be the only package we'll depend on. |
@jasonbosco doing this this._currentNodeIndex = (this._currentNodeIndex + 1) % this._nodes.length suggests that we're changing the nodes for every request regardless of whether the node at
|
@jasonbosco I want to understand the use of |
That’s correct
Correct, it’s just for logging purposes. I found this to be specially helpful when debugging which log line is for which retry attempt. |
As far as I've understood from gazing at the implementation in JavaScript and Python, here are the requirements summed up:
The main function is the
make_request
or equivalent. It's responsible for connecting with a node and completing the request. If anearestNode
is present in theConfiguration
, it'll try to connect to it given it'shealthy
, if not it'll fall back to thenodes
and use them in a round-robin fashion.I'm not sure how if a node is
healthy
is tracked? What I think: Every node starts with their health status as "fine" and when eventually if a request fails, that node is markedunhealthy
and the next node is tried until eventually due to round-robin this node is considered again, and if the request is successful this time, it's again markedhealthy
again?Also, is this where
numRetries
comes into play? In that, if a node fails to respond, we would try the same nodenumRetries
times?I'm also not sure about
healthcheckInterval
present in theConfiguration
class. What's its use?The text was updated successfully, but these errors were encountered: