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

[Pulsar SQL] Add max split entry queue size bytes limitation #9628

Merged

Conversation

gaoran10
Copy link
Contributor

@gaoran10 gaoran10 commented Feb 19, 2021

Motivation

In Pulsar SQL, there are two configurations pulsar.max-split-entry-queue-size and pulsar.max-split-message-queue-size to control the entry queue and message queue capacity, but some entries are so big some are small, it's hard to control the queue size bytes and the message queue size bytes.

Modifications

Add a new configuration pulsar.max-split-queue-cache-size to control the entry queue size bytes and the message queue size bytes. Half of this configuration will assign to entry queue size bytes and the left quota assign to message queue size bytes.

Verifying this change

  • Make sure that the change passes the CI checks.

(Please pick either of the following options)

This change is a trivial rework / code cleanup without any test coverage.

(or)

This change is already covered by existing tests, such as (please describe tests).

(or)

This change added tests and can be verified as follows:

(example:)

  • Added integration tests for end-to-end deployment with large payloads (10MB)
  • Extended integration test for recovery after broker failure

Does this pull request potentially affect one of the following parts:

If yes was chosen, please highlight the changes

  • Dependencies (does it add or upgrade a dependency): (no)
  • The public API: (no)
  • The schema: (no)
  • The default values of configurations: (no)
  • The wire protocol: (no)
  • The rest endpoints: (no)
  • The admin cli options: (no)
  • Anything that affects deployment: (no)

@gaoran10 gaoran10 changed the title [WIP] [Pulsar SQL] Add max split entry queue size bytes limitation [Pulsar SQL] Add max split entry queue size bytes limitation Feb 19, 2021
public class CacheSizeAllocator {

private final long maxCacheSize;
private final AtomicLong availableCacheSize;
Copy link
Member

Choose a reason for hiding this comment

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

Use LongAdder?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok

@@ -136,6 +137,10 @@ public PulsarRecordCursor(List<PulsarColumnHandle> columnHandles, PulsarSplit pu
pulsarConnectorConfig),
new PulsarConnectorMetricsTracker(pulsarConnectorCache.getStatsProvider()));
this.decoderFactory = decoderFactory;
if (pulsarConnectorConfig.getMaxSplitEntryQueueSizeBytes() >= 0) {
this.entryCacheSizeAllocator = new CacheSizeAllocator(
Copy link
Member

Choose a reason for hiding this comment

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

I think you can make it an interface. Then have a no-op implementation and a CacheSizeAllocator implementation. Then you don't need to add if (entryCacheSizeAllocator != null) everywhere else.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, that seems better.

@codelipenghui codelipenghui added the area/sql Pulsar SQL related features label Feb 24, 2021
@codelipenghui codelipenghui added this to the 2.8.0 milestone Feb 24, 2021
Copy link
Contributor

@codelipenghui codelipenghui left a comment

Choose a reason for hiding this comment

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

Please add unit tests for the changes to make sure the cache size allocator is initialized as expected.

@@ -136,6 +137,10 @@ public PulsarRecordCursor(List<PulsarColumnHandle> columnHandles, PulsarSplit pu
pulsarConnectorConfig),
new PulsarConnectorMetricsTracker(pulsarConnectorCache.getStatsProvider()));
this.decoderFactory = decoderFactory;
if (pulsarConnectorConfig.getMaxSplitEntryQueueSizeBytes() >= 0) {
Copy link
Contributor

Choose a reason for hiding this comment

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

If the size == 0, this means disabled?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If the config value is 0, there will be only one entry in the entry queue.

@codelipenghui
Copy link
Contributor

@gaoran10 Could you please check the comments?

@gaoran10 gaoran10 force-pushed the pulsar-sql-read-cache-size-limit branch from 39dc7e6 to 1c4051d Compare March 2, 2021 03:49
@gaoran10
Copy link
Contributor Author

gaoran10 commented Mar 2, 2021

/pulsarbot run-failure-checks

@@ -222,7 +228,7 @@ public void setPulsarSqlSchemaInfoProvider(PulsarSqlSchemaInfoProvider schemaInf
@VisibleForTesting
class DeserializeEntries implements Runnable {

protected boolean isRunning = false;
protected boolean isRunning = false;
Copy link
Member

Choose a reason for hiding this comment

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

is this introduced by mistake?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is an indent fix.

@@ -654,4 +671,15 @@ private void checkFieldType(int field, Class<?> expected) {
checkArgument(actual == expected, "Expected field %s to be type %s but is %s", field, expected, actual);
}

private void initEntryCacheSizeAllocator(PulsarConnectorConfig connectorConfig) {
log.info("Init entry cache size allocator with max split entry queue size bytes {}.",
Copy link
Member

Choose a reason for hiding this comment

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

Move this log message to the if block?


public long getAvailableCacheSize() {
try {
lock.readLock().lock();
Copy link
Member

Choose a reason for hiding this comment

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

Why do we need a lock?

cursor.asyncReadEntries(batchSize, maxSizeBytes,
this, System.nanoTime(), PositionImpl.latest);
} else {
metricsTracker.incr_READ_ATTEMPTS_FAIL();
Copy link
Member

Choose a reason for hiding this comment

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

If people doesn't configure this setting, we are initializing a NullCacheSizeAllocator. So it will cause metricsTracker to increase READ_ATTEMPTS_FAIL again and again.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh yes, I'll fix this.

@codelipenghui
Copy link
Contributor

@gaoran10 Could you please check sijie's comments?

@gaoran10
Copy link
Contributor Author

gaoran10 commented Mar 8, 2021

/pulsarbot run-failure-checks

@gaoran10 gaoran10 force-pushed the pulsar-sql-read-cache-size-limit branch from 94d62ac to 8e19763 Compare March 9, 2021 00:05
@gaoran10
Copy link
Contributor Author

gaoran10 commented Mar 9, 2021

/pulsarbot run-failure-checks

@codelipenghui codelipenghui merged commit 1f6ce7a into apache:master Mar 14, 2021
fmiguelez pushed a commit to fmiguelez/pulsar that referenced this pull request Mar 16, 2021
…9628)

### Motivation

In Pulsar SQL, there are two configurations `pulsar.max-split-entry-queue-size` and `pulsar.max-split-message-queue-size` to control the entry queue and message queue capacity, but some entries are so big some are small, it's hard to control the queue size bytes and the message queue size bytes.

### Modifications

Add a new configuration `pulsar.max-split-queue-cache-size` to control the entry queue size bytes and the message queue size bytes. Half of this configuration will assign to entry queue size bytes and the left quota assign to message queue size bytes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/sql Pulsar SQL related features
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants