Skip to content
This repository has been archived by the owner on Aug 2, 2021. It is now read-only.

Lookahead buffer for ServeContent #1876

Merged
merged 43 commits into from
Nov 12, 2019
Merged

Lookahead buffer for ServeContent #1876

merged 43 commits into from
Nov 12, 2019

Conversation

janos
Copy link
Member

@janos janos commented Oct 14, 2019

This is a naive approach to implement a io.ReadSeeker with a lookahead buffer to be used with potentially slower reads from provider reader and for http.ServeContent.

fixes #1524

@janos janos assigned janos and acud Oct 14, 2019
@janos janos added this to Backlog in Swarm Core - Sprint planning via automation Oct 14, 2019
@janos janos changed the title HTTP Lookahead buffer Lookahead buffer for ServeContent Oct 14, 2019
@janos janos moved this from Backlog to In progress in Swarm Core - Sprint planning Oct 25, 2019
@acud acud moved this from In progress to In review (includes Documentation) in Swarm Core - Sprint planning Oct 28, 2019
api/http/server.go Outdated Show resolved Hide resolved
case "buffered":
return langos.NewBufferedReadSeeker(s, getFileBufferSize)
case "langos":
return langos.NewBufferedLangos(s, getFileBufferSize)
Copy link
Member Author

Choose a reason for hiding this comment

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

We can use regular langos here (not buffered), also, since the peek tail is preserved. I do not get conclusive measurements that buffered one is faster at the current state.

Copy link
Member

@zelig zelig left a comment

Choose a reason for hiding this comment

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

LGTM, coulf not find any issues with this PR, other than

@janos janos requested a review from nonsense October 29, 2019 10:52
// NewLangos bakes a new yummy langos that peeks
// on provided reader when its Read method is called.
// Argument peekSize defines the length of peeks.
func NewLangos(r Reader, peekSize int) *Langos {
Copy link
Contributor

Choose a reason for hiding this comment

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

The package is called langos and this constructor is also called NewLangos, so ultimately we end up with langos.NewLangos which is not very user-friendly unless you are intrinsically familiar with this code. LookaheadBufferedReadSeeker or smth like that would be much better than langos imo.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, Langos is used as a codename and is not so descriptive. We can rename it, but it would be nice to have something shorter. Since this is the only codename in the package with the same name as the package. Maybe a package doc comment that describes what langos stands for would help.

@nonsense
Copy link
Contributor

nonsense commented Nov 7, 2019

It would have been nice if the PR has a summary of the results of this change. Has this been tested in a real-world setting where you have 20ms-150ms roundtrip times to nodes, and some chunk reads are orders of magnitude slower than others?

@janos
Copy link
Member Author

janos commented Nov 8, 2019

Thanks @nonsense for the review.

I did perform a series of tests on public swarm network, but was able to do so only before I merged backward incompatible changes and protocol versions bump. Results that I had were up to 2x faster download speed with buffered Langos then by using BufferedReadSeeker. Unfortunately, that was still during the development and I did not record results. I was uploading files (from 2 to 50MB) to one of the swarm gateway nodes and dowloaded them locally. For that, I had to raise SearchTimeout drastically in order to be able to have successful downloads.

Results with better connected nodes on a private cluster show much less performance gain. Average download speed on a standard smoke test jumps from 3.5Mb/s to 4.5MB/s and maximal download speed jump from 6MB/s to 8.5MB/s. Maximal download speed happens in frequent peeks.

master (buffered read seeker): master (buffered read seeker)
pr (langos): pr (langos)

@nonsense
Copy link
Contributor

nonsense commented Nov 8, 2019

@janos great work, based on your results this is definitely an improvement.

@janos
Copy link
Member Author

janos commented Nov 8, 2019

Thanks @nonsense. I expected more, but it is at least some improvement.

@janos janos merged commit 7c508c6 into master Nov 12, 2019
Swarm Core - Sprint planning automation moved this from In review (includes Documentation) to Done Nov 12, 2019
@janos janos deleted the lookahead-buffer branch November 12, 2019 09:21
@acud acud added this to the 0.5.3 milestone Nov 25, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
No open projects
Development

Successfully merging this pull request may close these issues.

extend http downloader with asynchronous lookahead
4 participants