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

feat: temporary session pool scaling? #56

Open
jxsl13 opened this issue Mar 15, 2024 · 1 comment
Open

feat: temporary session pool scaling? #56

jxsl13 opened this issue Mar 15, 2024 · 1 comment

Comments

@jxsl13
Copy link
Owner

jxsl13 commented Mar 15, 2024

now that we have a channel instead of a queue, we can now define a custom time based (and maybe event time + number of already active transient sessions) "session scaling" policy that allows to return a transient session after waiting for a while for sessions to be returned before trying to create a new transient connection + session.

@jxsl13
Copy link
Owner Author

jxsl13 commented Mar 26, 2024

something along the lines of this:

select {
    // sp = session pool
    case <-sp.ctx.Done():
        return nil, ErrClosed
    case <-ctx.Done():
        return nil, ctx.Err()
    case s, ok <- sp.sessions:
        if !ok{
            return nil, ErrClosed
        }
        return s, nil
    default:
        timeout, scale := sp.AutoScalePolicy(s.ActiveTransientConnections, s.ActiveTransientSessions)
        var waitChan chan time.Time = nil // blocking forever
        if scale {
            waitChan = time.After(timeout) // we might need to use an actual time.Timer here that can be properly closed when it is not needed anymore
        }

        select {
            case <-sp.ctx.Done():
                return nil, ErrClosed
            case <-ctx.Done():
                return nil, ctx.Err()
            case s, ok <- sp.sessions:
                if !ok {
                    return nil, ErrClosed
                }
                return s, nil
            case <-waitChan:
                return sp.GetTransientSession(ctx) // might need to use an unguarded variant of the method here
        }
    }
}

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

No branches or pull requests

1 participant