-
Notifications
You must be signed in to change notification settings - Fork 246
--cap-mbps refactor #3122
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
base: main
Are you sure you want to change the base?
--cap-mbps refactor #3122
Conversation
a.logger.Log(common.LogInfo, fmt.Sprintf("%s: Target Mbps %d", a.logPrefix, (a.targetBytesPerSecond()*8)/(1000*1000))) | ||
} | ||
// | ||
//var ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we just delete this file?
package common | ||
|
||
// NonBlockingSafeSend implements a channel send that is guaranteed to not panic, and may be either instantaneous or waiting. | ||
// Instantaneous returns false if a panic occurred, or if |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this comment is incomplete.
newAlloc uint64 | ||
} // when a request seeks, it should fire itself down this channel to manage its allocation | ||
|
||
shutdownCh chan bool |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see this being initialized in the constructor.
@@ -1,85 +1,85 @@ | |||
// Copyright © 2017 Microsoft <[email protected]> | |||
// // Copyright © 2017 Microsoft <[email protected]> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I noticed that the entire file is commented out. If it's no longer needed, should we consider removing it?
@@ -0,0 +1,22 @@ | |||
package ste |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this is a new file, we should add the Microsoft licensing header.
@@ -0,0 +1,31 @@ | |||
package ste |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same as above comment
@@ -0,0 +1,373 @@ | |||
package ste |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto
isLive: &atomic.Pointer[bool]{}, | ||
|
||
liveBodies: make(map[uuid.UUID]*policyPacerBody), | ||
requestInitChannel: make(chan *policyPacerBody, 300), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we can declare this as constant defaultBufferSize=300
common.AtomicSubtract(r.allocatedBytesPerSecond, PacerBodyMinimumBytesPerSecond) | ||
req.bodyStatus.Store(to.Ptr(BodyStatusDeallocated)) | ||
default: | ||
escape = true // break doesn't work in here |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we can do something like this.
for {
select {
case req := <-r.pacerExitChannel:
delete(r.liveBodies, req.id)
common.AtomicSubtract(r.allocatedBytesPerSecond, PacerBodyMinimumBytesPerSecond)
req.bodyStatus.Store(to.Ptr(BodyStatusDeallocated))
default:
return
}
}
// Inform the body that it is allocated | ||
newResponse.bodyStatus.Store(to.Ptr(BodyStatusAllocated)) | ||
default: | ||
escape = true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same as above
// Inform the body that it is allocated | ||
newRequest.bodyStatus.Store(to.Ptr(BodyStatusCompleted)) | ||
default: // there's nothing new, so let's use what we have. | ||
escape = true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same as above
// Inform the body that it is allocated | ||
newRequest.bodyStatus.Store(to.Ptr(BodyStatusAllocated)) | ||
default: // there's nothing new, so let's use what we have. | ||
escape = true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dittto
|
||
if resp != nil { | ||
n.parent.ProcessBytes(uint64(max(resp.ContentLength, 0))) | ||
} else if err == nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Question: Can both resp and err be nil? Normally, if err is nil, resp is expected to be non-nil.
However, it's good defensive coding to handle the rare case where a misbehaving policy or transport layer might return both as nil.
In such a case, we safely return the previously allocated bytes.
|
||
maxPacerGbps = 100 | ||
maxPacerBytesPerSecond = maxPacerGbps * 1000 * 1000 * 1000 / 8 | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've noticed that there are many constants defined across different files in the ste folder. Would it make sense to create a dedicated constants.go file under ste to centralize and manage all constants for better maintainability?
pacer := NewRequestPolicyPacer(targetBytesPerSecond) | ||
|
||
return &RequestPolicyAutoPacer{ | ||
RequestPolicyPacer: pacer, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit pick: RequestPolicyPacer: NewRequestPolicyPacer(targetBytesPerSecond),
corePolicy := r.RequestPolicyPacer.GetPolicy() | ||
|
||
return &autoPacerPolicy{ | ||
p: corePolicy, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we consider using a more meaningful variable name instead of p? Something like innerPolicy, wrappedPolicy, or corePolicy
@@ -0,0 +1,302 @@ | |||
package ste |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
msft licensing header required
BodyStatusNew BodyStatus = 0 | ||
BodyStatusAllocated BodyStatus = 1 | ||
BodyStatusCompleted BodyStatus = 2 | ||
BodyStatusDeallocated BodyStatus = -1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be moved to a separate constants file
if pol, ok := newPolicy.(policy.Policy); ok { | ||
return pol.Do(req) | ||
} else if pol != nil { | ||
return nil, fmt.Errorf("supplied policy for key %v was not a policy.Policy but a %v", p.policyKey, newPolicy) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we are checking the type of the policy, should we use %T here to clearly indicate the actual type received?
This one is gonna be a bit lengthy, and I'm still sorta in the depths of it.
At this point, most of the meat and potatoes are here, but this still isn't quite ready to go. It won't build yet. I'm reworking the page blob auto pacer around the new model. At that point, things need to be plugged in.
It's important to note, before review, what's majorly different:
I need to write tests for no bandwidth limit as well, because I don't trust that quite yet.