-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
A proposal for a network Resource Manager #1260
Comments
Linking this old issue for discoverability / visibility: #635. |
File descriptors are another resource we should probably track, as suggested by @Stebalien here: libp2p/go-libp2p-swarm#165. |
yeah, good point. |
I think this is a great approach but I'd like to question the hierarchy:
Really, I have:
I want to be able to configure constraints like:
|
In terms of implementation: We'd need a DMZ service and peer for "unknown" resources. Basically a holding ground where we have low limits and short timeouts.
|
Nit: I'd replace |
Yeah, these are all very good points.
There are definitely non hierarchical scopes at play.
I also agree with reserving buffers instead of actually getting them,
helper methods aside.
…On Thu, Dec 16, 2021, 05:42 Steven Allen ***@***.***> wrote:
Nit: I'd replace GetBuffer(size) []byte and friends with Reserve(size)
and Release(size). I would *definitely* provide helper methods for
allocating actual buffers, using a buffer pool, etc., but (a) not
everything is a buffer and (b) some services may need to manage their own
memory for some reason.
—
You are receiving this because you were assigned.
Reply to this email directly, view it on GitHub
<#1260 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAAI4SULA3BEAPOLWUQIRODURFN2RANCNFSM5JY2Z3PA>
.
|
Basically what we need to model here is the application/protocol as a trait. |
I think the right way to model this is the following graph:
Where the protocol is a set of applicable proto IDs or a default scope. |
I still want to make sure we have a strong motivation for this hierarchy:
|
Re 2: For services, I think we can add another scope, or replace the protocol scope with it. An argument could be made that we need both (see below). Re 1: For the limit hierarchy, it is easier to control resources without the user doing anything. |
Sure, but we don't need per-connection limits in that case. We'd need:
I'm just challenging the per-connection limits because I don't think that really buys us anything. |
It does buy us resource control before the hanshake, which seems kind of an important edge case. |
Yeah, but that's not really connection scoped. That is, it's not something using resources from the connection scope, it's the connection using resources from some "DMZ" scope. |
I have updated the pr, next iteration based on our sync discussion. The most notable changes:
LimitsWhen reserving resources, limits are checked at every step going upwards. Under root, we have services, which are constructs that track resources at the application level; the programmer must tell us about resources used by services and add streams explicitly. In parallel we have peers and protocol suites (the latter is useful so that the application programmer can get limits without doing any housekeeping himself). The low level resource scopes are streams (belonging to a peer and optionally owned by a service) and connections. Streams are rooted in peers, as we discussed. The DMZThe DMZ scope constrains unassociated connections and unnegotiated streams and related resources; it allows us to limit transient resource usage. Connection LifetimeOutbound ConnectionCreating a connection requires us to reserve the resource in the appropriate peer, with a limit check. Calling Inbound ConnectionInbound connections get a scope, initially constrained by the DMZ; once the connection has been negotiated, the transport calls Stream LifetimeOutbound StreamOutbound streams are created through the peer scope, with the user supplied list of protocols. This checks and reserves resources both at the peer level and at the protocol scope level. Inbound StreamInbound stream scopes are created through the peer scope without a protocol list. Once the protocol has been negotiated, it is explicitly set with Service Owned StreamsThe application may designate a stream as owned by a service; this allows us to apply per service limits. |
This is implemented now. |
Network Resource Management
The Problem
Our networking stack is currently a black hole in terms of resource
management; connections, streams, buffers and so on can consume
arbitrary resources with very little visibility.
In addition, an often requested feature is the ability to set hard
limits in terms of resources (esp. connections) that can be consumed
by the network stack, which we are not currently equipped to do.
Here we propose a network Resource Manager interface that can be
plugged at the bowels of the stack (transports and multiplexers) and
provide for the necessary resource accounting and limits.
Network Resources and Limits
The main entry point for resource consumption in the network stack is
the Connection. Each connection is associated with a peer, which may
have many active connnections. Associated with a connection may be
buffers and open streams for some protocol(s). Further down the
rabbit hole, streams have associated buffers.
This suggests a natural hierarchy for resource management:
This hierarchy creates an entry point for setting limits at the peer
level: We can limit per peer the number of connections it can have,
and further down the number of streams on each connection and on
aggregate for the peer. Similarly we can set a limit on how much
buffer space a peer can consume, with higher resolution on limiting
the buffer space consumed by each connection and each stream.
On top of per peer limits, the system may impose global hard limits
that restrain the aggregate resource usage. We may also want to set
per protocol limits globally.
Transactional Scopes for Resource Management
In order to make resource management ergonomic, we propose the concept
of transactional scopes for aggregate resource management. Starting
with a peer scope, we create a transactional scope for each connection
and similarly a transactional scope for each stream. Within we account
and limit resource usage, and once the top level scope is closed, then
all resources down the tree will also be released.
A potential subtle point is the association of a connection scope with
a peer; prior to the handshake in an incoming connection, we do not
yet know the peer. That implies that a connection scope can be created
without initially being associated with a peer, with the association
established later.
Using transactional scopes, we can sketch an interface for the resource manager as follows:
Notes
application protocol limits in a granular way.
TransactionalScope
interface implies that buffers are allocated (from the buffer pool)through the scope and not directly. We may want to do this indirectly by recording/vetting the
buffer size instead of the actual buffer.
The text was updated successfully, but these errors were encountered: