Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
63829: changefeedccl: Improve avro encoder performance r=miretskiy a=miretskiy

Avoid expensive allocations (maps) when encoding datums.
Improve encoder performance by ~40%, and significantly reduce
memory allocations per op.

```
BenchmarkEncodeInt-16                    1834214               665.4 ns/op            73 B/op          5 allocs/op
BenchmarkEncodeBool-16                   1975244               597.8 ns/op            33 B/op          3 allocs/op
BenchmarkEncodeFloat-16                  1773226               661.6 ns/op            73 B/op          5 allocs/op                                                  BenchmarkEncodeBox2D-16                   628884              1740 ns/op             579 B/op         18 allocs/op
BenchmarkEncodeGeography-16              1734722               713.3 ns/op           233 B/op          5 allocs/op                                                  BenchmarkEncodeGeometry-16               1495227              1208 ns/op            2737 B/op          5 allocs/op                                                  BenchmarkEncodeBytes-16                  2171725               698.4 ns/op            64 B/op          5 allocs/op                                                  BenchmarkEncodeString-16                 1847884               696.0 ns/op            49 B/op          4 allocs/op
BenchmarkEncodeDate-16                   2159253               701.6 ns/op            64 B/op          5 allocs/op
BenchmarkEncodeTime-16                   1857284               682.9 ns/op            81 B/op          6 allocs/op
BenchmarkEncodeTimeTZ-16                  833163              1405 ns/op             402 B/op         14 allocs/op
BenchmarkEncodeTimestamp-16              1623998               720.5 ns/op            97 B/op          6 allocs/op
BenchmarkEncodeTimestampTZ-16            1614201               719.0 ns/op            97 B/op          6 allocs/op
BenchmarkEncodeDecimal-16                 790902              1473 ns/op             490 B/op         23 allocs/op
BenchmarkEncodeUUID-16                   2216424               783.0 ns/op           176 B/op          6 allocs/op
BenchmarkEncodeINet-16                   1545225               817.6 ns/op           113 B/op          8 allocs/op
BenchmarkEncodeJSON-16                   2146824              1731 ns/op             728 B/op         21 allocs/op
```


Release Notes: None


63845: storage: pool pebbleReadOnly allocations r=nvanbenschoten a=nvanbenschoten

This commit introduces object pooling for `pebbleReadOnly` allocation avoidance. I found this to be important both because it avoids the initial `pebbleReadOnly` allocation, but also because it allows the memory recycling inside of each `pebbleIterator` owned by a `pebbleReadOnly` to work correctly.

I found this while running a few microbenchmarks and noticing that the lockTable's calls to `intentInterleavingReader` were resulting in a large number of heap allocations in `(*pebbleReadOnly).NewEngineIterator`. This was because `lowerBoundBuf` and `upperBoundBuf` were always nil and so each append (all 4 of them) in `(*pebbleIterator).init` was causing an allocation.

```
name                          old time/op    new time/op    delta
KV/Scan/Native/rows=1-16        30.9µs ± 4%    29.9µs ± 6%   -3.29%  (p=0.000 n=20+20)
KV/Scan/Native/rows=100-16      54.2µs ± 4%    52.7µs ± 5%   -2.84%  (p=0.002 n=20+20)
KV/Scan/Native/rows=10-16       34.0µs ± 3%    33.1µs ± 6%   -2.64%  (p=0.001 n=20+20)
KV/Scan/Native/rows=1000-16      253µs ± 5%     255µs ± 5%     ~     (p=0.659 n=20+20)
KV/Scan/Native/rows=10000-16    2.16ms ± 4%    2.14ms ± 3%     ~     (p=0.072 n=20+20)

name                          old alloc/op   new alloc/op   delta
KV/Scan/Native/rows=1-16        8.69kB ± 0%    7.49kB ± 0%  -13.79%  (p=0.000 n=20+19)
KV/Scan/Native/rows=10-16       10.1kB ± 0%     8.9kB ± 0%  -11.87%  (p=0.000 n=20+18)
KV/Scan/Native/rows=100-16      22.7kB ± 0%    21.5kB ± 0%   -5.29%  (p=0.000 n=17+19)
KV/Scan/Native/rows=1000-16      174kB ± 0%     172kB ± 0%   -0.66%  (p=0.000 n=19+19)
KV/Scan/Native/rows=10000-16    1.51MB ± 0%    1.51MB ± 0%   -0.05%  (p=0.000 n=16+19)

name                          old allocs/op  new allocs/op  delta
KV/Scan/Native/rows=1-16          71.0 ± 0%      62.0 ± 0%  -12.68%  (p=0.000 n=20+20)
KV/Scan/Native/rows=10-16         75.0 ± 0%      66.0 ± 0%  -12.00%  (p=0.000 n=20+19)
KV/Scan/Native/rows=100-16        79.0 ± 0%      70.0 ± 0%  -11.39%  (p=0.000 n=19+19)
KV/Scan/Native/rows=1000-16       87.8 ± 1%      79.0 ± 0%   -9.97%  (p=0.000 n=20+16)
KV/Scan/Native/rows=10000-16       113 ± 2%       103 ± 2%   -8.19%  (p=0.000 n=17+19)
```

We may want to consider this as a candidate to backport to release-21.1, because the lack of pooling here was even more detrimental with the separated lockTable, which creates a separate `EngineIterator` with lower and upper bounds. So this may have a small impact on #62078.

Release note (performance improvement): A series of heap allocations performed when serving read-only queries are now avoided.

63904: colbuilder: support 'CASE expr WHEN exprs' form r=yuzefovich a=yuzefovich

Previously, we didn't support `CASE expr WHEN exprs` form of CASE
expression and had to fallback to row-by-row engine. This form requires
just another step of performing an equality comparison of `expr`
against the projection of the current WHEN arm to decide whether this
arm matched. This commit does so.

Release note: None

63947: execinfra: mark 'sql.distsql.temp_storage.workmem' as public r=yuzefovich a=yuzefovich

Release note (sql change): `sql.distsql.temp_storage.workmem` cluster
setting is now marked as public and is included into the documentation.
It determines how much RAM a single operation of a single query can use
before it must spill to temporary storage. Note the operations that
don't support the disk spilling will ignore this setting and are subject
only to `--max-sql-memory` startup argument.

Co-authored-by: Yevgeniy Miretskiy <[email protected]>
Co-authored-by: Nathan VanBenschoten <[email protected]>
Co-authored-by: Yahor Yuzefovich <[email protected]>
  • Loading branch information
4 people committed Apr 21, 2021
5 parents b32bbb5 + 162b44d + f01e15d + d8ff84f + 1311fd1 commit 075aa5d
Show file tree
Hide file tree
Showing 9 changed files with 479 additions and 231 deletions.
1 change: 1 addition & 0 deletions docs/generated/settings/settings-for-tenants.txt
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ sql.defaults.results_buffer.size byte size 16 KiB default size of the buffer tha
sql.defaults.serial_normalization enumeration rowid default handling of SERIAL in table definitions [rowid = 0, virtual_sequence = 1, sql_sequence = 2, sql_sequence_cached = 3]
sql.defaults.statement_timeout duration 0s default value for the statement_timeout; default value for the statement_timeout session setting; controls the duration a query is permitted to run before it is canceled; if set to 0, there is no timeout
sql.distsql.max_running_flows integer 500 maximum number of concurrent flows that can be run on a node
sql.distsql.temp_storage.workmem byte size 64 MiB maximum amount of memory in bytes a processor can use before falling back to temp storage
sql.log.slow_query.experimental_full_table_scans.enabled boolean false when set to true, statements that perform a full table/index scan will be logged to the slow query log even if they do not meet the latency threshold. Must have the slow query log enabled for this setting to have any effect.
sql.log.slow_query.internal_queries.enabled boolean false when set to true, internal queries which exceed the slow query log threshold are logged to a separate log. Must have the slow query log enabled for this setting to have any effect.
sql.log.slow_query.latency_threshold duration 0s when set to non-zero, log statements whose service latency exceeds the threshold to a secondary logger on each node
Expand Down
1 change: 1 addition & 0 deletions docs/generated/settings/settings.html
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
<tr><td><code>sql.defaults.serial_normalization</code></td><td>enumeration</td><td><code>rowid</code></td><td>default handling of SERIAL in table definitions [rowid = 0, virtual_sequence = 1, sql_sequence = 2, sql_sequence_cached = 3]</td></tr>
<tr><td><code>sql.defaults.statement_timeout</code></td><td>duration</td><td><code>0s</code></td><td>default value for the statement_timeout; default value for the statement_timeout session setting; controls the duration a query is permitted to run before it is canceled; if set to 0, there is no timeout</td></tr>
<tr><td><code>sql.distsql.max_running_flows</code></td><td>integer</td><td><code>500</code></td><td>maximum number of concurrent flows that can be run on a node</td></tr>
<tr><td><code>sql.distsql.temp_storage.workmem</code></td><td>byte size</td><td><code>64 MiB</code></td><td>maximum amount of memory in bytes a processor can use before falling back to temp storage</td></tr>
<tr><td><code>sql.log.slow_query.experimental_full_table_scans.enabled</code></td><td>boolean</td><td><code>false</code></td><td>when set to true, statements that perform a full table/index scan will be logged to the slow query log even if they do not meet the latency threshold. Must have the slow query log enabled for this setting to have any effect.</td></tr>
<tr><td><code>sql.log.slow_query.internal_queries.enabled</code></td><td>boolean</td><td><code>false</code></td><td>when set to true, internal queries which exceed the slow query log threshold are logged to a separate log. Must have the slow query log enabled for this setting to have any effect.</td></tr>
<tr><td><code>sql.log.slow_query.latency_threshold</code></td><td>duration</td><td><code>0s</code></td><td>when set to non-zero, log statements whose service latency exceeds the threshold to a secondary logger on each node</td></tr>
Expand Down
1 change: 1 addition & 0 deletions pkg/ccl/changefeedccl/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ go_test(
"//pkg/util/span",
"//pkg/util/syncutil",
"//pkg/util/timeutil",
"//pkg/util/timeutil/pgdate",
"//pkg/util/uuid",
"//pkg/workload",
"//pkg/workload/bank",
Expand Down
Loading

0 comments on commit 075aa5d

Please sign in to comment.