Skip to content
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

Closed
wants to merge 8 commits into from
Closed

support wait conn on busy #668

wants to merge 8 commits into from

Conversation

king526
Copy link

@king526 king526 commented Oct 8, 2019

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.

func (c *HostClient) releaseConn(cc *clientConn) {
	c.connsLock.Lock()
	c.conns = append(c.conns, cc)
	c.connsLock.Unlock()
	select {
	case c.connNotify <- struct{}{}:
	default:
	}
}

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 .

dingliang added 3 commits October 8, 2019 14:30
(cherry picked from commit e626e8d)
(cherry picked from commit b16006d)
(cherry picked from commit 356b771)
@king526
Copy link
Author

king526 commented Oct 8, 2019

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.

@king526
Copy link
Author

king526 commented Oct 9, 2019

i think that ci has bug?

@king526 king526 closed this Oct 9, 2019
@king526 king526 reopened this Oct 9, 2019
client.go Outdated Show resolved Hide resolved
client.go Outdated Show resolved Hide resolved
@king526
Copy link
Author

king526 commented Oct 15, 2019

new commit is submited

@king526
Copy link
Author

king526 commented Oct 18, 2019

beated by the travis-ci, i am out.

@erikdubbelboer
Copy link
Collaborator

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!

Copy link
Collaborator

@erikdubbelboer erikdubbelboer left a 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
Copy link
Collaborator

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.

Copy link
Author

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.

Copy link
Collaborator

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
Copy link
Collaborator

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)
Copy link
Collaborator

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.

Copy link
Author

@king526 king526 Oct 25, 2019

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

Copy link
Collaborator

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++ {
Copy link
Collaborator

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)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
err2 := waitClient.DoTimeout(req, nil, time.Second*10)
err := waitClient.DoTimeout(req, nil, time.Second*10)

@erikdubbelboer
Copy link
Collaborator

Superseded by #764

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants