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

Idea: TCP Request pipelining support #160

Open
TysonAndre opened this issue Nov 1, 2022 · 2 comments
Open

Idea: TCP Request pipelining support #160

TysonAndre opened this issue Nov 1, 2022 · 2 comments

Comments

@TysonAndre
Copy link

TysonAndre commented Nov 1, 2022

Currently, gomemcache

  1. acquires a connection
  2. sends a request
  3. receives a response
  4. Releases a connection back to the connection pool

func (c *Client) onItem(item *Item, fn func(*Client, *bufio.ReadWriter, *Item) error) error {
addr, err := c.selector.PickServer(item.Key)
if err != nil {
return err
}
cn, err := c.getConn(addr)
if err != nil {
return err
}
defer cn.condRelease(&err)
if err = fn(c, cn.rw, item); err != nil {
return err
}
return nil
}

It's possible in the memcache protocol to send requests without waiting for the response (https://en.wikipedia.org/wiki/Protocol_pipelining) and this is done in various clients/proxies. This allows for lower resource usage (one connection instead of multiple connection, fewer syscalls, etc), and higher throughput when there is higher latency (e.g. memcached in a different datacenter)

Is this something you'd be interested in a PR for?

This is something I'd implemented in https://github.com/TysonAndre/golemproxy (a hackathon project to implement something easier to customize than twemproxy, e.g. for custom business logic to replicate commands or compare results. The source was combined to make the development cycle easier since I was the only one working on that, but the client remains as an independent component with a similar api. golemproxy worked in unit/integration tests)

golemproxy is a local memcache proxy written in Golang. Like twemproxy, it supports pipelining and shards requests to multiple servers.

(Another difference is that that repo accepts bytes instead of str, but that was because it was a proxy for clients that send/receive non-utf8 data, such as serialized data)

(The gomemcache project appeared inactive when I'd worked on that support, so I hadn't created a ticket then)

@bradfitz
Copy link
Owner

bradfitz commented Nov 1, 2022

Yes! Totally! This has been bugging me for 5+ years and is the reason why most PRs around connection management in this repo don't interest me too much; the core use of connections in this package just are wrong to begin with (not pipelined)

@TysonAndre
Copy link
Author

Okay, I should have time later this week to work on this

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

2 participants