Skip to content

[8.0] modelindexer: Reduce locking on flushActive (backport #7649)#7661

Merged
marclop merged 1 commit into
8.0from
mergify/bp/8.0/pr-7649
Mar 24, 2022
Merged

[8.0] modelindexer: Reduce locking on flushActive (backport #7649)#7661
marclop merged 1 commit into
8.0from
mergify/bp/8.0/pr-7649

Conversation

@mergify

@mergify mergify Bot commented Mar 24, 2022

Copy link
Copy Markdown
Contributor

This is an automatic backport of pull request #7649 done by Mergify.
Cherry-pick of b951097 has failed:

On branch mergify/bp/8.0/pr-7649
Your branch is up to date with 'origin/8.0'.

You are currently cherry-picking commit b951097a.
  (fix conflicts and run "git cherry-pick --continue")
  (use "git cherry-pick --skip" to skip this patch)
  (use "git cherry-pick --abort" to cancel the cherry-pick operation)

Changes to be committed:
	modified:   model/modelindexer/indexer.go

Unmerged paths:
  (use "git add <file>..." to mark resolution)
	both modified:   changelogs/head.asciidoc

To fix up this pull request, you can check it out locally. See documentation: https://docs.github.com/en/github/collaborating-with-pull-requests/reviewing-changes-in-pull-requests/checking-out-pull-requests-locally


Mergify commands and options

More conditions and actions can be found in the documentation.

You can also trigger Mergify actions by commenting on this pull request:

  • @Mergifyio refresh will re-evaluate the rules
  • @Mergifyio rebase will rebase this PR on its base branch
  • @Mergifyio update will merge the base branch into this PR
  • @Mergifyio backport <destination> will backport this PR on <destination> branch

Additionally, on Mergify dashboard you can:

  • look at your merge queues
  • generate the Mergify configuration with the config editor.

Finally, you can contact us on https://mergify.com

This patch unlocks the `i.activeMu` mutex in flushActive as soon as the
`i.active` reference has been set to `nil`. This severely minimizes the
lock contention and achives similar or higher indexing throughput when
comparing the benchmarks before #7352 was introduced.

The microbenchmark results seem to indicate that we're back to the
previous indexing performance with this change:

```console
$ go test -bench ... # Current main
goos: darwin
goarch: arm64
pkg: github.com/elastic/apm-server/model/modelindexer
BenchmarkModelIndexer/NoCompression-8        4653790    2527 ns/op
BenchmarkModelIndexer/BestSpeed-8            2909288	4051 ns/op
BenchmarkModelIndexer/DefaultCompression-8   1691677	6674 ns/op
BenchmarkModelIndexer/BestCompression-8      1234953    8334 ns/op
PASS
ok  	github.com/elastic/apm-server/model/modelindexer	70.585s
```

```console
$ go test -bench ... # This patch
goos: darwin
goarch: arm64
pkg: github.com/elastic/apm-server/model/modelindexer
BenchmarkModelIndexer/NoCompression-8         	 8702388	  1344 ns/op
BenchmarkModelIndexer/BestSpeed-8             	 5097385	  2238 ns/op
BenchmarkModelIndexer/DefaultCompression-8    	 2639126	  4821 ns/op
BenchmarkModelIndexer/BestCompression-8       	 1586126	  7350 ns/op
PASS
ok  	github.com/elastic/apm-server/model/modelindexer	64.933s
```

The contention is much worse when the APM Server is actually running and
indexing against an Elasticsearch cluster since the lock is held for the
entire `bulkIndexer.Flush` operation, which includes network latency.

Signed-off-by: Marc Lopez Rubio <marc5.12@outlook.com>
(cherry picked from commit b951097)

# Conflicts:
#	changelogs/head.asciidoc
@mergify mergify Bot added the conflicts There is a conflict in the backported pull request label Mar 24, 2022
@ghost

ghost commented Mar 24, 2022

Copy link
Copy Markdown

💚 Build Succeeded

the below badges are clickable and redirect to their specific view in the CI or DOCS
Pipeline View Test View Changes Artifacts preview preview

Expand to view the summary

Build stats

  • Start Time: 2022-03-24T13:08:30.950+0000

  • Duration: 26 min 9 sec

Test stats 🧪

Test Results
Failed 0
Passed 5162
Skipped 19
Total 5181

🤖 GitHub comments

To re-run your PR in the CI, just comment with:

  • /test : Re-trigger the build.

  • /hey-apm : Run the hey-apm benchmark.

  • /package : Generate and publish the docker images.

  • /test windows : Build & tests on Windows.

  • run elasticsearch-ci/docs : Re-trigger the docs validation. (use unformatted text in the comment!)

@marclop marclop merged commit 98f3959 into 8.0 Mar 24, 2022
@marclop marclop deleted the mergify/bp/8.0/pr-7649 branch March 24, 2022 15:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

conflicts There is a conflict in the backported pull request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant