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

IGNITE-22977 #4227

Open
wants to merge 19 commits into
base: main
Choose a base branch
from
Open

IGNITE-22977 #4227

wants to merge 19 commits into from

Conversation

ascherbakoff
Copy link
Contributor

@ascherbakoff ascherbakoff commented Aug 13, 2024

https://issues.apache.org/jira/browse/IGNITE-22977

This patch adds following optimizations:

  1. clock.now() uses FastTimestamp with 1 millisecond precision
  2. Reduced completablefuture chains
  3. Optimized schema validation before the tx operation
  4. Optimized waiting on lease validation
  5. Row id generator no longer uses SecureRandom

Performance gain is about 17% according to added UpsertKvBenchmark with current master #9672234bf81b35ee367138238d5585293d910fcc
Other improvements will be done in separate tickets (like IGNITE-20869)

public static final String SKIP_REPLICATION_IN_BENCHMARK = "SKIP_REPLICATION_IN_BENCHMARK";

/** Skip storage update in a benchmark. */
public static final String SKIP_STORAGE_UPDATE_IN_BENCHMARK = "SKIP_STORAGE_UPDATE_IN_BENCHMARK";
Copy link
Contributor

Choose a reason for hiding this comment

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

I want that both of these properties have "IGNITE_" prefix.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

🆗

) {
@Override
public <R> CompletableFuture<R> run(Command cmd) {
return cmd.getClass().getSimpleName().contains("UpdateCommand") ? nullCompletedFuture() : super.run(cmd);
Copy link
Contributor

Choose a reason for hiding this comment

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

I worry that if the class name changes, the code will become useless.

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 not possible to fix due to dependency issues. UpdateCommand is not available in raft module.

executor,
commandsMarshaller
);
boolean inBenchmark = IgniteSystemProperties.getBoolean(IgniteSystemProperties.SKIP_REPLICATION_IN_BENCHMARK, false);
Copy link
Contributor

Choose a reason for hiding this comment

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

False is the default.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

🆗

@@ -2795,26 +2761,28 @@ private CompletableFuture<CompletableFuture<?>> applyUpdateCommand(
return resultFuture.thenApply(res -> {
UpdateCommandResult updateCommandResult = (UpdateCommandResult) res;

if (full && !updateCommandResult.isPrimaryReplicaMatch()) {
if (full && updateCommandResult != null && !updateCommandResult.isPrimaryReplicaMatch()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this is done to handle a test result (SKIP_REPLICATION_IN_BENCHMARK).
Maybe it would be better to give the correct response to avoid this checking.

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 not possible due to dependency issues. The response class is not available in raft module.

* @return Next row id.
*/
public static UUID next() {
return new UUID(FastTimestamps.coarseCurrentTimeMillis(), ThreadLocalRandom.current().nextLong());
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it enough to have 64 random bits? Is using 2 random longs too slow?

Copy link
Contributor Author

@ascherbakoff ascherbakoff Aug 19, 2024

Choose a reason for hiding this comment

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

My intention to use a timestamp is to reduce duplicate value probability due to periodical nature of a generator.
Both variants seem equal from perf point of view.
I'm ok with both, but prefer to leave as is if you have no arguments against.

Copy link
Contributor

Choose a reason for hiding this comment

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

It seems that 64 bits per millisecond is ok

@Nullable HybridTimestamp opTs = getTxOpTimestamp(request);
@Nullable HybridTimestamp opTsIfDirectRo = (request instanceof ReadOnlyDirectReplicaRequest) ? opTs : null;
@Nullable HybridTimestamp txTs = getTxStartTimestamp(request);
if (txTs == null) {
Copy link
Contributor

Choose a reason for hiding this comment

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

It seems safer to switch to request instanceof ReadOnlyDirectReplicaRequest condition (or at least assert it)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There is no need in such check or assertion.
txTs can be assigned to non null value only if request instanceof ReadOnlyDirectReplicaRequest

Copy link
Contributor

Choose a reason for hiding this comment

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

In the current code this is true, but if we change the code, we can inadvertently break this implicit invariant. An assertion would help to make it explicit.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Don't think this code will change in the future.

}
};

if (lockFut.isDone() && !lockFut.isCompletedExceptionally()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if (lockFut.isDone() && !lockFut.isCompletedExceptionally()) {
if (CompletableFutures.isCompletedSuccessfully(lockFut)) {

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.

4 participants