Skip to content

#9986 [functions] [WIP] - Allow Cluster-Wide and Function-Specific Producer Defaults - #9987

Closed
devinbost wants to merge 19 commits into
apache:masterfrom
devinbost:disable-function-batching
Closed

devinbost wants to merge 19 commits into
apache:masterfrom
devinbost:disable-function-batching

Conversation

@devinbost

@devinbost devinbost commented Mar 20, 2021 •

Copy link
Copy Markdown
Contributor

New Feature of Pulsar

This feature introduces the ability to modify default producer behavior of Pulsar functions at two levels of granularity:

  1. Cluster-wide, through configuration changes to functions_worker.yml
  2. On a function-specific basis.

When a cluster-admin modifies function producer defaults in functions_worker.yml, they are able to change the behavior of ALL functions through a single config change. This enables widespread changes to be easily implemented in function producer behavior. This PR introduces the ability to modify these defaults:

  • batchingEnabled
  • chunkingEnabled
  • blockIfQueueFull
  • compressionType
  • hashingScheme
  • messageRoutingMode
  • batchingMaxPublishDelay

If specific functions require default settings that deviate from the cluster-wide defaults, functions can override the cluster defaults via their configuration.

Motivation

Pulsar currently provides no way to allow users or operators to change the producing behavior of Pulsar functions. For organizations that are making heavy use of functions, the ability to tune behavior is greatly desired. Moreover, current defaults appear to be causing issues for certain workloads. Enabling operators to modify these defaults to workaround issues will enable those operators to upgrade legacy versions of Pulsar to more recent versions by using changes to function defaults to temporarily workaround bugs (such as with batching, as mentioned in #6054.)

Modifications

WorkerConfig was modified to support an additional set of parameters (for cluster-wide defaults.)
I introduced a mechanism to validate the configurations when they are set, and any problems with the configurations will throw a new exception type to ensure the cluster-admin notices the exact problem on broker startup. I also added some basic string processing when loading the configurations to ensure that differences in casing or use of hyphens/underscores won't break configurations (since that's a common source of very annoying configuration bugs.)

Adding function-specific defaults required modifying the protobuf function definition. I introduced several enums to allow "UNKNOWN" to be provided as an option (since protobuf doesn't support null primitives.)

I introduced a new class that handles the logic of determining whether to use cluster-wide defaults or function-specific defaults. In case the function-specific defaults are invalid, the error is logged to inform the user that there was a problem with their function configuration. In a separate PR, exceptions could be thrown during function deployment when invalid configurations are provided, but that seemed potentially out of scope for this PR. (I'm open to adding that if it seems very important though.)

Additional functionality could easily be added to make the cluster configuration startup validation even more robust, and a similar approach could be taken to validate other Pulsar configurations to simplify use for new cluster operators and for existing cluster operators who are experimenting with new cluster configurations. (Nobody likes to try starting Pulsar only to discover that it won't start due to a configuration error.)

Because FunctionDetails are available in different code paths than the WorkerConfig for many locations, I created a second class that behaves like a proxy to simplify implementation instead of requiring every code path to have both class objects available.

I also ensured that this change will apply to all runtimes (process mode, thread mode, kubernetes mode, localrun.)

I have not yet added the function-specific overrides to Go or Python functions, but those would be easy changes to make in separate PRs.

Fixes #9986

This PR will also help us determine if disabling function batching prevents the freezing topic issue on high-velocity production topics (#6054). If disabling function batching doesn't actually stop freezing topics, that information will help in root cause analysis of what's causing those freezing topics (or unresponsive subscriptions.)

Verifying this change

I created a new test class with selective mocking that verifies the behavior of the new functionality. It also verifies that the new configurations can be correctly loaded and that function configurations correctly override cluster-wide defaults when (and only when) they are provided. Unfortunately, I was unable to mock the protobuf classes because they are final, so I had to work around that in my tests.

This change is covered by existing tests:

  • Many tests already touch WorkerConfig and FunctionDetails. What else needs to be tested in this PR?

This change added tests and can be verified as follows:

  • Run TestClusterFunctionProducerDefaults
  • Run existing tests, especially any that were updated by this PR

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, except between some Pulsar modules)
  • The public API: (yes, users can set new parameters when deploying function)
  • The schema: (don't know)
  • The default values of configurations: (POTENTIALLY -- I preserved defaults to conform to existing behavior, but some values were inconsistent across the framework, such as values for batchingMaxPublishDelay)
  • The wire protocol: (yes) (added property to protobuf definition of function)
  • The rest endpoints: (potentially due to new additions to the protobuf function definition)
  • The admin cli options: (new parameters were added for local run options)
  • Anything that affects deployment: (not in a negative way)

Documentation

  • Does this pull request introduce a new feature? (yes)
  • If yes, how is the feature documented? (documentation will be added in a separate PR or in additional commits to this PR)

@devinbost

Copy link
Copy Markdown
Contributor Author

I'd like help with getting this included in the release of Pulsar 2.8.0.
@jerrypeng @sijie @codelipenghui @lhotari @rdhabalia

@eolivelli

Copy link
Copy Markdown
Contributor

I am not sure I understand if this fix is resolving your problem or it is only a mitigation.

@devinbost

Copy link
Copy Markdown
Contributor Author

I am not sure I understand if this fix is resolving your problem or it is only a mitigation.

It's only a mitigation for now, but it's still a useful feature for anyone who wants to disable function message batching for any other reason.

category = CATEGORY_FUNCTIONS,
doc = "Enables message batching between functions"
)
private boolean isFunctionBatchingEnabledDefault = true;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This seems like a one-off config as in the there are no other configs in worker configs that define defaults for certain function configs. If we are going to let cluster admin set defaults for function configs at a cluster level, we should do it in a more comprehensive manner and not just have one-off configs like this.

@jerrypeng jerrypeng left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Will I am in favor of allowing users to configure whether functions should enable batching or not. I am not in favor of creating a "default" config for the enabling batching in worker config. This seems like a one-off thing as worker config currently does not define defaults for other function configs. I am in favor of creating a way for cluster admins to be able to define defaults for certain function configs at a cluster level, but it needs to be a more comprehensive mechanism and not just one-off configs.

@devinbost

Copy link
Copy Markdown
Contributor Author

Will I am in favor of allowing users to configure whether functions should enable batching or not. I am not in favor of creating a "default" config for the enabling batching in worker config. This seems like a one-off thing as worker config currently does not define defaults for other function configs. I am in favor of creating a way for cluster admins to be able to define defaults for certain function configs at a cluster level, but it needs to be a more comprehensive mechanism and not just one-off configs.

Thanks for the feedback. I appreciate your review. What would that more comprehensive mechanism look like to you? Would the defaults still go into WorkerConfig?
We could populate an object with additional default settings, but we'd need a way to map each default setting to a destination, which could be a method call (such as when building the function producer) or a property set (such as on a function config). Since there's a lot of variation in how those defaults might need to be applied, it's not clear to me how that should be done in a general way. Perhaps we could use reflection to lookup what needs to be set or called at runtime (for applying a particular default), but that would increase the risk of user problems at startup.

@devinbost

devinbost commented Mar 22, 2021 •

Copy link
Copy Markdown
Contributor Author

One of the challenges is that protobuf doesn't support null primitives, so it's not as simple as just checking the function config for a null and then using the corresponding WorkerConfig default if the function config property is null. If we just rely on the function config's default value for the default behavior, then there's no way for a cluster admin to change all the functions' behavior with one config change. (Instead, every function would need to be re-deployed.)

I suppose I could create a new kind of ProducerBuilder (such as ProducerBuilderWithDefaults) that would be passed an object with the Function defaults and the WorkerConfig's function defaults, and it would provide the logic for each builder method to check the Function default, and if it's set to the protobuf default value, then it assumes the Function default was equivalent to "null" and then uses the corresponding property on the object with the WorkerConfig's function defaults.

With that said, it doesn't look like each producer implementation uses pulsar.getProducerBuilder()... some of them use client.newProducer(..) (such as in PulsarSink, https://github.com/apache/pulsar/blob/master/pulsar-functions/instance/src/main/java/org/apache/pulsar/functions/sink/PulsarSink.java#L110), but I'm not sure we want to also expose all that to the client by creating a new client builder method like newProducerWithDefaults because I don't think the client should need to know those details.

@devinbost

Copy link
Copy Markdown
Contributor Author

It looks like I can use the loadConf method on ProducerBuilderImpl (https://github.com/apache/pulsar/blob/master/pulsar-client/src/main/java/org/apache/pulsar/client/impl/ProducerBuilderImpl.java#L121), so that might be cleaner than needing to decorate the ProducerBuilder with one that has builder methods that set defaults.

@devinbost devinbost changed the title #9986 [functions] - Allow Disabling of Function Batching #9986 [functions] [WIP] - Allow Disabling of Function Batching Mar 23, 2021
@devinbost devinbost changed the title #9986 [functions] [WIP] - Allow Disabling of Function Batching #9986 [functions] [WIP] - Allow Cluster-Wide and Function-Specific Producer Defaults Mar 23, 2021
@jerrypeng

Copy link
Copy Markdown
Contributor

@devinbost in WorkerConfig, we can add a new field call defaultFunctionConfig/defaultSourceConfig/defaultSinkConfig or defaultFunctionConfigFile/defaultSourceConfigFile/defaultSinkConfigFile if we just want to point to a separate file.

In the worker config could look something like


workerId: standalone
workerHostname: localhost
...
defaultFunctionConfig:
  producerConfig: 
    maxPendingMessages: 100
    enableBatching: true

On registering the function, we merge the user provided function config with the default function config.

@devinbost

Copy link
Copy Markdown
Contributor Author

/pulsarbot run-failure-checks

2 similar comments
@devinbost

Copy link
Copy Markdown
Contributor Author

/pulsarbot run-failure-checks

@devinbost

Copy link
Copy Markdown
Contributor Author

/pulsarbot run-failure-checks

@devinbost

Copy link
Copy Markdown
Contributor Author

I have not been able to reproduce these test failures locally. Additional eyes would be helpful.

@devinbost

Copy link
Copy Markdown
Contributor Author

/pulsarbot run-failure-checks

1 similar comment
@devinbost

Copy link
Copy Markdown
Contributor Author

/pulsarbot run-failure-checks

@devinbost
devinbost force-pushed the disable-function-batching branch from c7fb1b5 to 5bce7c1 Compare March 27, 2021 04:35
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.

[Functions] Need a way to disable message batching between functions

3 participants