Andrey Yarovoy created HDDS-17032:
-------------------------------------

             Summary: Avoid building the `Preconditions` message on every write 
in `ECKeyOutputStream.ECChunkBuffers.addToDataBuffer`
                 Key: HDDS-17032
                 URL: https://issues.apache.org/jira/browse/HDDS-17032
             Project: Apache Ozone
          Issue Type: Bug
          Components: EC Client
            Reporter: Andrey Yarovoy


**Problem**

`ECChunkBuffers.addToDataBuffer` runs once per `write()` call segment. It 
checks the cell position with an eagerly
concatenated message:

```java
Preconditions.checkState(pos <= cellSize,
"Position(" + pos + ") is greater than the cellSize(" + cellSize + ").");
```

The message string is built (`StringConcatFactory` → `Integer.getChars`) on 
every call, even though the check
virtually never fails. The number of calls scales with the caller's write size. 
freon's default `--buffer` is 4096
bytes, which means about 65,000 calls per 256 MB key, and applications doing 
small writes pay the same.

**Evidence** (real-cluster async-profiler wall profile, JDK 17, writer threads, 
on-CPU samples)

| Writers | Share of writer CPU spent building this message |
|---|---|
| 1 rs-3-2-1024k writer | 0.79% |
| 16 rs-3-2-1024k writers | 1.81% |

**Proposal**

Use Guava's template overload with primitive arguments, so nothing is formatted 
or boxed unless the check fails:

```java
Preconditions.checkState(pos <= cellSize,
"Position(%s) is greater than the cellSize(%s).", pos, cellSize);
```

The other `Preconditions` call on the per-stripe path (`generateParityCells`) 
already uses a template. The
eagerly built message in `close()` (`writeOffset == offset`) runs once per key, 
so it is not worth changing.

**Compatibility**

No behaviour change: the same exception type and message when the check fails.

**Testing**

Existing `TestECKeyOutputStream` / `TestOzoneECClient`. No new test is needed; 
the message text is unchanged.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to