Skip to content

chore: Add source plugin benchmark#415

Merged
kodiakhq[bot] merged 7 commits intomainfrom
source-plugin-benchmark
Nov 21, 2022
Merged

chore: Add source plugin benchmark#415
kodiakhq[bot] merged 7 commits intomainfrom
source-plugin-benchmark

Conversation

@hermanschaaf
Copy link
Copy Markdown
Contributor

@hermanschaaf hermanschaaf commented Nov 18, 2022

This adds a source plugin benchmark that runs in-memory. It allows for different scenarios to be set up, but currently comes with only two: one scenario without child tables, and one with child tables.

Here are the results on my machine:

BenchmarkDefaultConcurrency
BenchmarkDefaultConcurrency-8                     	       1	     11637 resources/s	     12626 targetResources/s	73510696 B/op	 1032412 allocs/op
BenchmarkTablesWithChildrenDefaultConcurrency
BenchmarkTablesWithChildrenDefaultConcurrency-8   	       1	       544.6 resources/s	     40606 targetResources/s	461292456 B/op	 6689992 allocs/op
PASS

The output is different from normal Go benchmarks, and I feel it better fits our use-case. It shows the actual resources/s, similar to what the CLI would show. It also shows a targetResources/s, an attempt to calculate the theoretical best value we could aim for.

As the above results show, we are doing pretty well in the case with no child relations, but we are leaving a lot of room for improvement when child relations are involved. In theory, these could be sped up by almost 100x (this might use a lot of memory though, of course). In both cases it seems like we could also be doing better in terms of number of allocs and B/op, but that is pending further research.

Closes cloudquery/cloudquery#3721

@disq
Copy link
Copy Markdown
Member

disq commented Nov 18, 2022

goos: darwin
goarch: arm64
pkg: github.com/cloudquery/plugin-sdk/plugins
BenchmarkDefaultConcurrency
BenchmarkDefaultConcurrency-10                      	       1	     11994 resources/s	     12626 targetResources/s	73615560 B/op	 1032619 allocs/op
BenchmarkTablesWithChildrenDefaultConcurrency
BenchmarkTablesWithChildrenDefaultConcurrency-10    	       1	       540.1 resources/s	     40606 targetResources/s	461383256 B/op	 6690320 allocs/op
PASS

Same targetResources result? that's weird?

@hermanschaaf
Copy link
Copy Markdown
Contributor Author

@disq That's expected - it's a theoretical maximum we calculate, so you have something to compare the resources/s value to. It'll be unique for every test scenario, but it should never change (unless we refine the calculation)

@disq
Copy link
Copy Markdown
Member

disq commented Nov 18, 2022

@disq That's expected - it's a theoretical maximum we calculate, so you have something to compare the resources/s value to. It'll be unique for every test scenario, but it should never change (unless we refine the calculation)

Yes interesting calculation 👀

s.b.Fatal(err)
}

end := time.Now()
Copy link
Copy Markdown
Member

@disq disq Nov 21, 2022

Choose a reason for hiding this comment

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

diff := time.Since(start) (there's no call to s.b.StopTimer() now?)

Copy link
Copy Markdown
Contributor

@yevgenypats yevgenypats left a comment

Choose a reason for hiding this comment

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

Looks great! we can add benchtest in follow-up PR.

@kodiakhq kodiakhq bot merged commit 962f3f7 into main Nov 21, 2022
@kodiakhq kodiakhq bot deleted the source-plugin-benchmark branch November 21, 2022 14:11
kodiakhq bot pushed a commit that referenced this pull request Nov 21, 2022
This changes the resolver for table relations to work concurrently, like parent tables. To do so safely and without the risk of deadlock, we instantiate one semaphore per depth level. (The size of the semaphore is decreased logarithmically for each depth.)

This change will only improve performance for tables with child relations.

To compare the performance before and after, I used the benchmarks in #415

## Before
```
goos: darwin
goarch: arm64
pkg: github.com/cloudquery/plugin-sdk/plugins
BenchmarkDefaultConcurrency-8                     	       1	     11957 resources/s	     12626 targetResources/s	73597280 B/op	 1032425 allocs/op
BenchmarkTablesWithChildrenDefaultConcurrency-8   	       1	       545.9 resources/s	     40606 targetResources/s	461622584 B/op	 6690105 allocs/op
PASS
ok  	github.com/cloudquery/plugin-sdk/plugins	150.596s
```

## After
```
goos: darwin
goarch: arm64
pkg: github.com/cloudquery/plugin-sdk/plugins
BenchmarkDefaultConcurrency-8                     	       1	     11373 resources/s	     12626 targetResources/s	73692608 B/op	 1033614 allocs/op
BenchmarkTablesWithChildrenDefaultConcurrency-8   	       1	     30162 resources/s	     40606 targetResources/s	464285672 B/op	 6697508 allocs/op
PASS
ok  	github.com/cloudquery/plugin-sdk/plugins	6.241s
```

## Analysis

This change focuses on the `BenchmarkTablesWithChildrenDefaultConcurrency` case. The change improves `resources/s` from 545.9 to 30162, an improvement of about 55x. Memory and allocs are mostly the same.

The small downward change in `resources/s` in the `BenchmarkDefaultConcurrency` case is likely due to the few additional allocs needed. 

Closes #358
kodiakhq bot pushed a commit that referenced this pull request Nov 23, 2022
This changes the resolver for table relations to work concurrently, like parent tables. To do so safely and without the risk of deadlock, we instantiate one semaphore per depth level. (The size of the semaphore is decreased logarithmically for each depth.)

This change will only improve performance for tables with child relations.

To compare the performance before and after, I used the benchmarks in #415

## Before
```
goos: darwin
goarch: arm64
pkg: github.com/cloudquery/plugin-sdk/plugins
BenchmarkDefaultConcurrency-8                     	       1	     11957 resources/s	     12626 targetResources/s	73597280 B/op	 1032425 allocs/op
BenchmarkTablesWithChildrenDefaultConcurrency-8   	       1	       545.9 resources/s	     40606 targetResources/s	461622584 B/op	 6690105 allocs/op
PASS
ok  	github.com/cloudquery/plugin-sdk/plugins	150.596s
```

## After
```
goos: darwin
goarch: arm64
pkg: github.com/cloudquery/plugin-sdk/plugins
BenchmarkDefaultConcurrency-8                     	       1	     11373 resources/s	     12626 targetResources/s	73692608 B/op	 1033614 allocs/op
BenchmarkTablesWithChildrenDefaultConcurrency-8   	       1	     30162 resources/s	     40606 targetResources/s	464285672 B/op	 6697508 allocs/op
PASS
ok  	github.com/cloudquery/plugin-sdk/plugins	6.241s
```

## Analysis

This change focuses on the `BenchmarkTablesWithChildrenDefaultConcurrency` case. The change improves `resources/s` from 545.9 to 30162, an improvement of about 55x. Memory and allocs are mostly the same.

The small downward change in `resources/s` in the `BenchmarkDefaultConcurrency` case is likely due to the few additional allocs needed. 

Closes #358
Copy of #416 after it was reverted to schedule its release for another time.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Introduce performance benchmark

3 participants