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

exp/ingest/ledgerbackend: Wrap metaPipe in bufio.Reader #2763

Merged
merged 2 commits into from
Jun 30, 2020

Conversation

bartekn
Copy link
Contributor

@bartekn bartekn commented Jun 30, 2020

PR Checklist

PR Structure

  • This PR has reasonably narrow scope (if not, break it down into smaller PRs).
  • This PR avoids mixing refactoring changes with feature changes (split into two PRs
    otherwise).
  • This PR's title starts with name of package that is most changed in the PR, ex.
    services/friendbot, or all or doc if the changes are broad or impact many
    packages.

Thoroughness

  • This PR adds tests for the most critical parts of the new functionality or fixes.
  • I've updated any docs (developer docs, .md
    files, etc... affected by this change). Take a look in the docs folder for a given service,
    like this one.

Release planning

  • I've updated the relevant CHANGELOG (here for Horizon) if
    needed with deprecations, added features, breaking changes, and DB schema changes.
  • I've decided if this PR requires a new major/minor version according to
    semver, or if it's mainly a patch change. The PR is targeted at the next
    release branch if it's not a patch change.

What

Wraps metaPipe in stellarCoreRunner in bufio.Reader. This improves the speed of reading from a meta pipe.

Why

In 936bc3a we removed bufio.Reader based on an observation that it slows down reading from a pipe. However, after running a CPU profiler on reingestion code to debug another change I realized that a lot of time is spent on reading from a pipe in methods like xdr.Decoder.DecodeInt or xdr.Decoder.DecodeUint (that read just 4 bytes):

Screenshot 2020-06-30 at 12 22 27

When reingesting 1000 ledgers all executions of this method take 17% of entire run time! It was clear that there's an overhead time connected to reading from a pipe. After wrapping meta pipe in bufio.Reader the speed of reingestion of the same range improved by 25% (this isn't affected by Stellar-Core init time, the timer starts after PrepareRange is done).

Before:

INFO[2020-06-30T12:03:44.671+02:00] Reingestion done     duration=74.352344343 from=29999000 pid=44533 service=expingest to=30000000

After:

INFO[2020-06-30T12:06:14.829+02:00] Reingestion done     duration=55.449094814 from=29999000 pid=45181 service=expingest to=30000000

The change in 936bc3a solves the problems with reflection used in XDR decoder being slow. This commit mitigates issues with overhead time added when reading from a pipe.

Known limitations

It's worth checking if there is a similar speed improvement on linux systems (I'm running MacOS), it can be system dependent.

@bartekn bartekn requested a review from a team June 30, 2020 10:30
@cla-bot cla-bot bot added the cla: yes label Jun 30, 2020
@bartekn
Copy link
Contributor Author

bartekn commented Jun 30, 2020

@2opremio because you have more in-depth info about this, do you want to check before I merge?

@2opremio
Copy link
Contributor

2opremio commented Jun 30, 2020

I did, I just didn't approve because Tamir already had.

@bartekn bartekn merged commit c21ef0f into stellar:release-horizon-v1.6.0 Jun 30, 2020
@bartekn bartekn deleted the captive-bufio-pipe branch June 30, 2020 16:51
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

Successfully merging this pull request may close these issues.

3 participants