-
-
Notifications
You must be signed in to change notification settings - Fork 15.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reduce the perceived time taken to retrieve initialSeedUniquifier
Motivation: When system is in short of entrophy, the initialization of ThreadLocalRandom can take at most 3 seconds. The initialization occurs when ThreadLocalRandom.current() is invoked first time, which might be much later than the moment when the application has started. If we start the initialization of ThreadLocalRandom as early as possible, we can reduce the perceived time taken for the retrieval. Modification: Begin the initialization of ThreadLocalRandom in InternalLoggerFactory, potentially one of the firstly initialized class in a Netty application. Make DefaultChannelId retrieve the current process ID before retrieving the current machine ID, because retrieval of a machine ID is more likely to use ThreadLocalRandom.current(). Use a dummy channel ID for EmbeddedChannel, which prevents many unit tests from creating a ThreadLocalRandom instance. Result: We gain extra 100ms at minimum for initialSeedUniquifier generation. If an application has its own initialization that takes long enough time and generates good amount of entrophy, it is very likely that we will gain a lot more.
- Loading branch information
Showing
6 changed files
with
190 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
transport/src/main/java/io/netty/channel/embedded/EmbeddedChannelId.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/* | ||
* Copyright 2014 The Netty Project | ||
* | ||
* The Netty Project licenses this file to you under the Apache License, | ||
* version 2.0 (the "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at: | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package io.netty.channel.embedded; | ||
|
||
import io.netty.channel.ChannelId; | ||
|
||
/** | ||
* A dummy {@link ChannelId} implementation. | ||
*/ | ||
final class EmbeddedChannelId implements ChannelId { | ||
|
||
private static final long serialVersionUID = -251711922203466130L; | ||
|
||
static final ChannelId INSTANCE = new EmbeddedChannelId(); | ||
|
||
private EmbeddedChannelId() { } | ||
|
||
@Override | ||
public String asShortText() { | ||
return toString(); | ||
} | ||
|
||
@Override | ||
public String asLongText() { | ||
return toString(); | ||
} | ||
|
||
@Override | ||
public int compareTo(ChannelId o) { | ||
if (o == INSTANCE) { | ||
return 0; | ||
} | ||
|
||
return asLongText().compareTo(o.asLongText()); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return super.hashCode(); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object obj) { | ||
return super.equals(obj); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "embedded"; | ||
} | ||
} |