-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
support wait conn on busy #668
Conversation
on my first version.i just wait util get a new conns which no use time.After. i think it's efficient but not sure if it is rational. |
i think that ci has bug? |
new commit is submited |
beated by the travis-ci, i am out. |
Sorry I'm currently working on some changes that will make our travis-ci build more stable. Just ignore it for now. I'll have time this weekend to look at your pull request! |
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.
Thank you for the changes. I have a couple more requests.
if !c.PreferWaitConn { | ||
return nil, ErrNoFreeConns | ||
} | ||
<-c.connNotify |
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 really like this implementation. This way if a conn doesn't free up before the deadline we still have to wait for one to free up before we continue here. So we might be waiting much longer than our timeout.
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 will reconsider the implementation, there can be a better choose. since timer is inefficiency, i made this choose because it will not blocking api ,since we certainly use DoTimeout rather than Do. in our ad serving,5120 conns is set but sometime it still get a lot of no free conns error at monment.i do think it's necessary to take a action.
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.
You could just select
between c.connNotify
and a timer that signals at deadline
(using AcquireTimer
).
@@ -49,6 +50,7 @@ type Request struct { | |||
|
|||
// To detect scheme changes in redirects | |||
schemaUpdate bool | |||
deadline time.Time |
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 would prefer that instead of adding this field to ʼRequestʼ you add an extra parameter to ʼdoNonNilReqRespʼ etc.
s := &Server{ | ||
Handler: func(ctx *RequestCtx) { | ||
atomic.AddInt32(&serverGot, 1) | ||
time.Sleep(time.Second * 3) |
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.
Nice test. But can it also work with a bit shorter times? Maybe tens of milliseconds instead of seconds. That way our test suite doesn't take that long.
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.
ci should take this bag
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 understand? People making changes to fasthttp will run go test
locally and having to wait an extra 3 seconds for this is very annoying. The test should work just as fine if this was time.Millisecond * 30
and below time.Millisecond * 100
.
wg.Add(1) | ||
go func() { | ||
defer wg.Done() | ||
for j := 0; j < 1; j++ { |
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 loop does only one iteration so it can be removed.
for j := 0; j < 1; j++ { | ||
req := &Request{} | ||
req.SetRequestURI(addr) | ||
err2 := waitClient.DoTimeout(req, nil, time.Second*10) |
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.
err2 := waitClient.DoTimeout(req, nil, time.Second*10) | |
err := waitClient.DoTimeout(req, nil, time.Second*10) |
Superseded by #764 |
support wait conn on busy ,it is aim at avoid make too much conns which i think will make performance problem. thanks for reviewing and i had make same change.
i do not think lost notify will cause problem. waiting is no guarantee on continuous heavy requests.it is crop traffic on a time bucket (timeout) not for make requests ordered .