-
Notifications
You must be signed in to change notification settings - Fork 233
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
Cache Provider Records in the network #386
Comments
Yes and No. According to your quote the time t that we store the data corresponding to H is c*2^-d where d is some key space distance metric and c is some preset coefficient. If we use the distance from H instead of from V then c will need to be very large in order to make the cache times non-negligible. However, if c is some preset coefficient then it depends on properties like network size (i.e. not really a constant). This leaves us with some options:
I'd prefer option 2 (or even 1) over 3 since 3 makes DoS attacks on particular record updates much easier than 1 or 2 do. |
@aschmahmann I see exactly what you mean. Because distance(N, H) is potentially >> num_nodes(N,V). Given that 2^-d for us will be in [1, 2] (min d = 1, max d = 2^32 -1), we will have to choose c (based on the network size) carefully to come up with a meaningful expiry time in millis. Let me come up with a rudimentary TODO. |
Hmm, I now realise that we currently do not/should not allow a node to register another node as a provider which means this caching protocol can not work for us for Provider Records in it's current form. I think using it for PutValue records first makes more sense. TODO
@aschmahmann @Stebalien Please let me know your thoughts. |
Problem
In Kademlia, the K (20 for now) closest nodes to the hash H of some content are responsible for serving the providers for that content. As described quite well in libp2p/specs#163, as the content gets more popular, these nodes get overburdened since all provider lookups converge onto them. This creates both performance & availability problems.
Solution
The kademlia paper suggests caching records like so:
Basically, once a node has finished fetching the providers for hash H from the network, it should store the providers on the node N closest to the hash H that did not return the providers when it was traversing the network. This expands the radius of providers & future queries for H from nodes further from H than N will discover the cached providers before they bother the K closest nodes.
This distributes provider lookups across the network & prevents them from converging on & congesting the same path.
Cache Eviction
From the kad paper:
Basically, the further a node N is away from a node V which is the node that's closest to hash H in the whole network, the faster the expiry of the cached providers on N. This makes intuitive sense because queries for hash H from any node move closer & closer to V with each hop. So, the closer a node is to V, the higher the probability that it will be on a provider lookup path than a node that's further from V.
Question: Can't we simply use the XOR distance between N & H to determine expiry time rather than number of nodes between N & V since that is not trivial to do in our current implementation
Testing
libp2p testlab FTW !
@raulk @Stebalien
The text was updated successfully, but these errors were encountered: