Skip to content
This repository was archived by the owner on Jan 24, 2024. It is now read-only.

Conversation

@BewareMyPower
Copy link
Collaborator

@BewareMyPower BewareMyPower commented Jan 17, 2022

Motivation

Currently when the metrics related to Kafka requests are updated, a PrometheusStatsLogger will be created each time a request arrived.

            requestStats.getStatsLogger()
                    .scopeLabel(KopServerStats.REQUEST_SCOPE, apiName)

The StatsLogger#scopeLabel method calls scope method:

    public StatsLogger scope(String name) {
        return new PrometheusStatsLogger(provider, completeName(name), labels);
    }

The newly created PrometheusStatsLogger object is nearly the same with the caller itself except the name. The shared provider field is responsible to maintain the cache of Prometheus stats.

Therefore, there is no need to create another object if the name keeps the same. This PR is to avoid the redundant small object creations of PrometheusStatsLogger.

Modifications

Maintain a ConcurrentHashMap for each channel. The key is the ApiVersions object that represents a Kafka request's type, the value is the associated StatsLogger object.

In addition, since a RequestStats instance is associated with only one StatsLogger instance, this PR creates the RequestStats instance at the beginning and avoid creating the instance for each connection.

@BewareMyPower BewareMyPower added type/enhancement Indicates an improvement to an existing feature release/2.9.1 release/2.8.2.x labels Jan 17, 2022
@BewareMyPower BewareMyPower self-assigned this Jan 17, 2022
@BewareMyPower BewareMyPower changed the title Maintain a StatsLogger map to avoid creating new object every time [WIP] Maintain a StatsLogger map to avoid creating new object every time Jan 18, 2022
@BewareMyPower BewareMyPower changed the title [WIP] Maintain a StatsLogger map to avoid creating new object every time Maintain a StatsLogger map to avoid creating new object every time Jan 18, 2022
@BewareMyPower BewareMyPower merged commit 0a47184 into streamnative:master Jan 20, 2022
@BewareMyPower BewareMyPower deleted the bewaremypower/stats-logger-optimize branch January 20, 2022 02:17
BewareMyPower added a commit that referenced this pull request Jan 23, 2022
…1021)

### Motivation

Currently when the metrics related to Kafka requests are updated, a `PrometheusStatsLogger` will be created each time a request arrived.

```java
            requestStats.getStatsLogger()
                    .scopeLabel(KopServerStats.REQUEST_SCOPE, apiName)
```

The `StatsLogger#scopeLabel` method calls `scope` method:

```java
    public StatsLogger scope(String name) {
        return new PrometheusStatsLogger(provider, completeName(name), labels);
    }
```

The newly created `PrometheusStatsLogger` object is nearly the same with the caller itself except the name. The shared `provider` field is responsible to maintain the cache of Prometheus stats.

Therefore, there is no need to create another object if the name keeps the same. This PR is to avoid the redundant small object creations of `PrometheusStatsLogger`.

### Modifications

Maintain a `ConcurrentHashMap` for each channel. The key is the `ApiVersions` object that represents a Kafka request's type, the value is the associated `StatsLogger` object.

In addition, since a `RequestStats` instance is associated with only one `StatsLogger` instance, this PR creates the `RequestStats` instance at the beginning and avoid creating the instance for each connection.
BewareMyPower added a commit that referenced this pull request Jan 23, 2022
…1021)

### Motivation

Currently when the metrics related to Kafka requests are updated, a `PrometheusStatsLogger` will be created each time a request arrived.

```java
            requestStats.getStatsLogger()
                    .scopeLabel(KopServerStats.REQUEST_SCOPE, apiName)
```

The `StatsLogger#scopeLabel` method calls `scope` method:

```java
    public StatsLogger scope(String name) {
        return new PrometheusStatsLogger(provider, completeName(name), labels);
    }
```

The newly created `PrometheusStatsLogger` object is nearly the same with the caller itself except the name. The shared `provider` field is responsible to maintain the cache of Prometheus stats.

Therefore, there is no need to create another object if the name keeps the same. This PR is to avoid the redundant small object creations of `PrometheusStatsLogger`.

### Modifications

Maintain a `ConcurrentHashMap` for each channel. The key is the `ApiVersions` object that represents a Kafka request's type, the value is the associated `StatsLogger` object.

In addition, since a `RequestStats` instance is associated with only one `StatsLogger` instance, this PR creates the `RequestStats` instance at the beginning and avoid creating the instance for each connection.
BewareMyPower added a commit that referenced this pull request Feb 9, 2022
…1021)

### Motivation

Currently when the metrics related to Kafka requests are updated, a `PrometheusStatsLogger` will be created each time a request arrived.

```java
            requestStats.getStatsLogger()
                    .scopeLabel(KopServerStats.REQUEST_SCOPE, apiName)
```

The `StatsLogger#scopeLabel` method calls `scope` method:

```java
    public StatsLogger scope(String name) {
        return new PrometheusStatsLogger(provider, completeName(name), labels);
    }
```

The newly created `PrometheusStatsLogger` object is nearly the same with the caller itself except the name. The shared `provider` field is responsible to maintain the cache of Prometheus stats.

Therefore, there is no need to create another object if the name keeps the same. This PR is to avoid the redundant small object creations of `PrometheusStatsLogger`.

### Modifications

Maintain a `ConcurrentHashMap` for each channel. The key is the `ApiVersions` object that represents a Kafka request's type, the value is the associated `StatsLogger` object.

In addition, since a `RequestStats` instance is associated with only one `StatsLogger` instance, this PR creates the `RequestStats` instance at the beginning and avoid creating the instance for each connection.

(cherry picked from commit 0a47184)
eolivelli pushed a commit to eolivelli/kop that referenced this pull request Feb 24, 2022
…treamnative#1021)

Currently when the metrics related to Kafka requests are updated, a `PrometheusStatsLogger` will be created each time a request arrived.

```java
            requestStats.getStatsLogger()
                    .scopeLabel(KopServerStats.REQUEST_SCOPE, apiName)
```

The `StatsLogger#scopeLabel` method calls `scope` method:

```java
    public StatsLogger scope(String name) {
        return new PrometheusStatsLogger(provider, completeName(name), labels);
    }
```

The newly created `PrometheusStatsLogger` object is nearly the same with the caller itself except the name. The shared `provider` field is responsible to maintain the cache of Prometheus stats.

Therefore, there is no need to create another object if the name keeps the same. This PR is to avoid the redundant small object creations of `PrometheusStatsLogger`.

Maintain a `ConcurrentHashMap` for each channel. The key is the `ApiVersions` object that represents a Kafka request's type, the value is the associated `StatsLogger` object.

In addition, since a `RequestStats` instance is associated with only one `StatsLogger` instance, this PR creates the `RequestStats` instance at the beginning and avoid creating the instance for each connection.

(cherry picked from commit 0a47184)
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants