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

[improve][broker] PIP-192: Define new load manager base interfaces #18084

Conversation

Demogorgon314
Copy link
Member

Master Issue: #16691

Motivation

We will start raising PRs to implement PIP-192, #16691

Modifications

The PR adds base classes for the new broker load balance project and does not integrate with the existing load balance logic. This PR should not impact the existing broker load balance behavior.

For the pip-192 project, this PR

  • defines the base interface under org.apache.pulsar.broker.loadbalance.extensible package.
  • defines this BrokerRegistry public interface and its expected behaviors.
  • defines BrokerFilter interfaces.
  • defines LoadDataReporter interfaces.
  • defines NamespaceBundleSplitStrategy interfaces.
  • defines LoadManagerScheduler interfaces.
  • defines NamespaceUnloadStrategy interfaces.
  • defines LoadDataStore interfaces.
  • defines ExtensibleLoadManager interfaces.
  • defines LoadManagerContext interfaces.
  • defines BrokerLoadData and BrokerLookupData data classes.

Documentation

  • doc
  • doc-required
  • doc-not-needed
  • doc-complete

Matching PR in forked repository

PR in forked repository: Demogorgon314#4

@Demogorgon314 Demogorgon314 self-assigned this Oct 18, 2022
@Demogorgon314 Demogorgon314 changed the title PIP-192: Define new load manager base interfaces [improve][broker] PIP-192: Define new load manager base interfaces Oct 18, 2022
@github-actions github-actions bot added the doc-not-needed Your PR changes do not impact docs label Oct 18, 2022
@Demogorgon314 Demogorgon314 marked this pull request as ready for review October 18, 2022 11:30
Copy link
Contributor

@heesung-sn heesung-sn left a comment

Choose a reason for hiding this comment

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

Hi, this looks great to me.

I have some minor general comments.

  • let's trim some of the public functions in these interfaces if not used.
  • let's use generic terms, e.g. service unit instead of bundle(so that the functionality can be more "extensible").
  • let's try to use record classes as much as we can.

@Demogorgon314 Demogorgon314 added type/feature The PR added a new feature or issue requested a new feature area/broker type/PIP labels Oct 26, 2022
@heesung-sn
Copy link
Contributor

heesung-sn commented Nov 8, 2022 via email

@heesung-sn
Copy link
Contributor

heesung-sn commented Nov 8, 2022 via email

@Demogorgon314
Copy link
Member Author

Demogorgon314 commented Nov 9, 2022

@heesung-sn Use org.apache.pulsar.broker.loadbalance.overlord ok to me. But it looks like pulsar never used a creative name as the package name before. Not sure others develop agree with this.

@eolivelli
Copy link
Contributor

eolivelli commented Nov 9, 2022 via email

@heesung-sn
Copy link
Contributor

heesung-sn commented Nov 9, 2022 via email

@Demogorgon314 Demogorgon314 force-pushed the PIP-192-New_Load_Manager_Base_Classes branch from 5e7dad5 to 2458fbe Compare November 10, 2022 01:49
@Demogorgon314 Demogorgon314 force-pushed the PIP-192-New_Load_Manager_Base_Classes branch from 2458fbe to 07e8ab9 Compare November 14, 2022 04:13
@Demogorgon314
Copy link
Member Author

Copy link
Contributor

@BewareMyPower BewareMyPower left a comment

Choose a reason for hiding this comment

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

It's better to add line breaks to all files. If you are using Intellij Idea, Go to Editor - General, click Ensure every saved file ends with a line break.

@Demogorgon314 Demogorgon314 force-pushed the PIP-192-New_Load_Manager_Base_Classes branch from 07e8ab9 to 5cb7b56 Compare November 18, 2022 02:27
@codecov-commenter
Copy link

codecov-commenter commented Nov 18, 2022

Codecov Report

Merging #18084 (6534ce0) into master (7975023) will decrease coverage by 15.56%.
The diff coverage is 19.19%.

Impacted file tree graph

@@              Coverage Diff              @@
##             master   #18084       +/-   ##
=============================================
- Coverage     45.62%   30.05%   -15.57%     
+ Complexity    10075     6824     -3251     
=============================================
  Files           697      762       +65     
  Lines         68024    72901     +4877     
  Branches       7293     7812      +519     
=============================================
- Hits          31033    21911     -9122     
- Misses        33413    47978    +14565     
+ Partials       3578     3012      -566     
Flag Coverage Δ
unittests 30.05% <19.19%> (-15.57%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
...er/loadbalance/extensions/data/BrokerLoadData.java 0.00% <0.00%> (ø)
.../loadbalance/extensions/data/BrokerLookupData.java 0.00% <0.00%> (ø)
...oadbalance/extensions/data/TopBundlesLoadData.java 0.00% <0.00%> (ø)
...lance/extensions/store/LoadDataStoreException.java 0.00% <0.00%> (ø)
...nt/impl/PulsarClientImplementationBindingImpl.java 72.41% <ø> (-0.47%) ⬇️
...ar/client/impl/conf/ConsumerConfigurationData.java 92.55% <ø> (+2.12%) ⬆️
...he/pulsar/client/impl/TypedMessageBuilderImpl.java 30.76% <59.37%> (+3.56%) ⬆️
...n/java/org/apache/pulsar/client/api/RawReader.java 0.00% <0.00%> (-100.00%) ⬇️
...ava/org/apache/pulsar/broker/admin/v1/Brokers.java 0.00% <0.00%> (-100.00%) ⬇️
...ava/org/apache/pulsar/broker/admin/v2/Brokers.java 0.00% <0.00%> (-100.00%) ⬇️
... and 230 more

/**
* Defines the information required to broker lookup.
*/
public record BrokerLookupData (String webServiceUrl,
Copy link
Member

Choose a reason for hiding this comment

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

Refer PIP-192, this record should be LocalBrokerData?

Copy link
Member Author

Choose a reason for hiding this comment

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

IMO, BrokerLookupData maybe better since we already have a LocalBrokerData class (it contains lookup data and load data) in the old load manager impl. This record should only have lookup data.

The load data has split to BrokerLoadData.

Copy link
Member

Choose a reason for hiding this comment

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

Thanks for your explain. Maybe we can change PIP-192.

* @param serviceUnit service unit (e.g. bundle).
* @return Simple resource.
*/
CompletableFuture<Optional<LookupResult>> assign(Optional<ServiceUnitId> topic, ServiceUnitId serviceUnit);
Copy link
Member

Choose a reason for hiding this comment

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

Who is to invoke this method? Should the method return BrokerLookupData? We should minimize coupling with the current implementation.

/**
* Async push load data to store.
*
* @param key The load data key. (e.g. bundle)
Copy link
Member

Choose a reason for hiding this comment

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

What are the elements of a bundle? Should there be a namespace to distinguish?

Copy link
Member Author

Choose a reason for hiding this comment

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

Here is just an example. Actually, we always use the broker lookup service address as the key. I will remove this example, and explain it in impl class.

@Demogorgon314 Demogorgon314 requested review from eolivelli, heesung-sn and BewareMyPower and removed request for heesung-sn November 22, 2022 15:40
@heesung-sn
Copy link
Contributor

Lgtm

Copy link
Contributor

@eolivelli eolivelli left a comment

Choose a reason for hiding this comment

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

I have left only one major comment, apart from that I am +1 to this patch

* @param pulsarService Pulsar service to use.
* @return A set of the bundles that should be split.
*/
Set<Split> findBundlesToSplit(LoadManagerContext context, PulsarService pulsarService);
Copy link
Contributor

Choose a reason for hiding this comment

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

why do we need to pass PulsarService pulsarService here ?
it is not an "interface" so we are leaking some "implementation details"

in any case....won't it be injected to implementations at construction time ?

Copy link
Member Author

Choose a reason for hiding this comment

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

Updated.

Copy link
Contributor

@eolivelli eolivelli left a comment

Choose a reason for hiding this comment

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

LGTM

*/
@Data
public class BrokerLoadData {
private static final double gigaBitToByte = 128 * 1024 * 1024.0;
Copy link
Contributor

Choose a reason for hiding this comment

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

We have org.apache.pulsar.client.api.SizeUnit

I think we can add a method in SizeUnit

    public double toBytes(double value) {
        return value * bytes;
    }

And use the SizeUnit directly.

Copy link
Member Author

Choose a reason for hiding this comment

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

I have removed some temporary unused methods from BrokerLoadData. I think we can add it when we use it.

Copy link
Member Author

Choose a reason for hiding this comment

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

Comment on lines 167 to 187
private static double maxWithinLimit(double limit, double...args) {
double max = 0.0;
for (double d : args) {
if (d > max && d <= limit) {
max = d;
}
}
return max;
}

private static double max(double...args) {
double max = Double.NEGATIVE_INFINITY;

for (double d : args) {
if (d > max) {
max = d;
}
}

return max;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Duplicated with LocalBrokerData

public double getMaxResourceUsageWithExtendedNetworkSignal(ServiceConfiguration conf) {

double nicSpeedBytesInSec = getNicSpeedBytesInSec(conf);
return maxWithinLimit(100.0d,
Copy link
Contributor

Choose a reason for hiding this comment

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

And we can't apply the limitation of resource usage.
#18598 has provided more details.

@Demogorgon314 Demogorgon314 force-pushed the PIP-192-New_Load_Manager_Base_Classes branch from 6534ce0 to 8e2240e Compare November 30, 2022 12:41
@Demogorgon314 Demogorgon314 merged commit fd9444c into apache:master Dec 2, 2022
lifepuzzlefun pushed a commit to lifepuzzlefun/pulsar that referenced this pull request Jan 10, 2023
…pache#18084)

Master Issue: apache#16691

### Motivation

We will start raising PRs to implement PIP-192, apache#16691

### Modifications

The PR adds base classes for the new broker load balance project and does not integrate with the existing load balance logic. This PR should not impact the existing broker load balance behavior.

For the pip-192 project, this PR

* defines the base interface under `org.apache.pulsar.broker.loadbalance.extensible` package.
* defines this `BrokerRegistry` public interface and its expected behaviors.
* defines `BrokerFilter` interfaces.
* defines `LoadDataReporter` interfaces.
* defines `NamespaceBundleSplitStrategy` interfaces.
* defines `LoadManagerScheduler` interfaces.
* defines `NamespaceUnloadStrategy` interfaces.
* defines `LoadDataStore` interfaces.
* defines `ExtensibleLoadManager` interfaces.
* defines `LoadManagerContext` interfaces.
* defines `BrokerLoadData` and `BrokerLookupData` data classes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/broker doc-not-needed Your PR changes do not impact docs ready-to-test type/feature The PR added a new feature or issue requested a new feature type/PIP
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants