AngersZhuuuu opened a new pull request #30139:
URL: https://github.com/apache/spark/pull/30139
<!--
Thanks for sending a pull request! Here are some tips for you:
1. If this is your first time, please read our contributor guidelines:
https://spark.apache.org/contributing.html
2. Ensure you have added or run the appropriate tests for your PR:
https://spark.apache.org/developer-tools.html
3. If the PR is unfinished, add '[WIP]' in your PR title, e.g.,
'[WIP][SPARK-XXXX] Your PR title ...'.
4. Be sure to keep the PR description updated to reflect all changes.
5. Please write your PR title to summarize what this PR proposes.
6. If possible, provide a concise example to reproduce the issue for a
faster review.
7. If you want to add a new configuration, please read the guideline first
for naming configurations in
'core/src/main/scala/org/apache/spark/internal/config/ConfigEntry.scala'.
-->
### What changes were proposed in this pull request?
<!--
Please clarify what changes you are proposing. The purpose of this section
is to outline the changes and how this PR fixes the issue.
If possible, please consider writing useful notes for better and faster
reviews in your PR. See the examples below.
1. If you refactor some codes with changing classes, showing the class
hierarchy will help reviewers.
2. If you fix some SQL features, you can provide some references of other
DBMSes.
3. If there is design documentation, please add the link.
4. If there is a discussion in the mailing list, please add the link.
-->
### Why are the changes needed?
<!--
Please clarify why the changes are needed. For instance,
1. If you propose a new API, clarify the use case for a new API.
2. If you fix a bug, you can clarify why it is a bug.
-->
### Does this PR introduce _any_ user-facing change?
<!--
Note that it means *any* user-facing change including all aspects such as
the documentation fix.
If yes, please clarify the previous behavior and the change this PR proposes
- provide the console output, description and/or an example to show the
behavior difference if possible.
If possible, please also clarify if this is a user-facing change compared to
the released Spark versions or within the unreleased branches such as master.
If no, write 'No'.
-->
### How was this patch tested?
Test as below:
```
@Test
public void testChunkBenchmark() {
RpcHandler rpcHandler = new NoOpRpcHandler();
OneForOneStreamManager manager = (OneForOneStreamManager)
(rpcHandler.getStreamManager());
Map<Integer, List<Long>> streamsSizeList = new HashMap<>();
streamsSizeList.put(10000, new ArrayList<>());
streamsSizeList.put(50000, new ArrayList<>());
streamsSizeList.put(100000, new ArrayList<>());
int retryTimes = 10;
ExecutorService pool = Executors.newFixedThreadPool(100,
new
ThreadFactoryBuilder().setDaemon(true).setNameFormat("TestChunkBenchMark" +
"-%d").build());
for (int retry = 0; retry < retryTimes; retry++) {
Map<Integer, Runnable> requests = new HashMap<>();
Map<Integer, List<Pair<Object, ExtendedChannelPromise>>> responses =
new HashMap<>();
List<Future> tasks = new ArrayList<>();
for (int streamsSize : streamsSizeList.keySet()) {
for (int index = 0; index < streamsSize; index++) {
ChannelHandlerContext context = mock(ChannelHandlerContext.class);
Channel channel = mock(Channel.class);
when(context.channel())
.thenAnswer(invocationOnMock0 -> channel);
List<Pair<Object, ExtendedChannelPromise>> responseAndPromisePairs
=
new ArrayList<>();
when(channel.writeAndFlush(any()))
.thenAnswer(invocationOnMock0 -> {
Object response = invocationOnMock0.getArguments()[0];
ExtendedChannelPromise channelFuture = new
ExtendedChannelPromise(channel);
responseAndPromisePairs.add(ImmutablePair.of(response,
channelFuture));
return channelFuture;
});
long streamId = registerStream(channel, manager);
Runnable run = () -> {
try {
TransportClient reverseClient = mock(TransportClient.class);
ChunkFetchRequestHandler requestHandler = new
ChunkFetchRequestHandler(reverseClient,
rpcHandler.getStreamManager(), Long.MAX_VALUE, false);
RequestMessage request0 = new ChunkFetchRequest(new
StreamChunkId(streamId, 0));
requestHandler.channelRead(context, request0);
RequestMessage request1 = new ChunkFetchRequest(new
StreamChunkId(streamId, 1));
requestHandler.channelRead(context, request1);
RequestMessage request2 = new ChunkFetchRequest(new
StreamChunkId(streamId, 2));
requestHandler.channelRead(context, request2);
} catch (Exception e) {
throw new RuntimeException("Request failed", e.getCause());
}
};
requests.put(index, run);
responses.put(index, responseAndPromisePairs);
}
Assert.assertEquals(streamsSize, manager.numStreamStates());
Long start = System.currentTimeMillis();
for (Runnable request : requests.values()) {
tasks.add(pool.submit(request));
}
for (Future task : tasks) {
try {
task.get();
} catch (InterruptedException e) {
e.printStackTrace();
} catch (ExecutionException e) {
e.printStackTrace();
}
}
streamsSizeList.get(streamsSize).add(System.currentTimeMillis() -
start);
for (List<Pair<Object, ExtendedChannelPromise>> result :
responses.values()) {
Assert.assertEquals(3 , result.size());
}
}
}
System.out.println("OneForOneStreamManager fetch data duration test:");
System.out.println("Stream Size Max Min
Avg");
for (int streamsSize : streamsSizeList.keySet()) {
System.out.println(streamsSize + " " +
streamsSizeList.get(streamsSize).stream().mapToLong(x ->
x).max().getAsLong() + " " +
streamsSizeList.get(streamsSize).stream().mapToLong(x ->
x).min().getAsLong() + " " +
streamsSizeList.get(streamsSize).stream().mapToLong(x ->
x).average().getAsDouble());
}
}
private long registerStream(Channel channel, OneForOneStreamManager
manager) {
List<ManagedBuffer> managedBuffers = new ArrayList<>();
managedBuffers.add(new TestManagedBuffer(10));
managedBuffers.add(new TestManagedBuffer(20));
managedBuffers.add(new TestManagedBuffer(30));
long streamId = manager.registerStream("test-app",
managedBuffers.iterator(), channel);
return streamId;
}
```
Got result :
```
/**
* With patch:
* OneForOneStreamManager fetch data duration test:
* Stream Size Max Min Avg
* 10000 1172 189 444.8
* 50000 4594 1204 2260.4
* 100000 7081 2531 4813.0
*
* Process finished with exit code 0
*
* Without patch:
* OneForOneStreamManager fetch data duration test:
* Stream Size Max Min Avg
* 10000 2100 733 1203.0
* 50000 26148 20125 22594.5
* 100000 153909 95787 130210.3
*
* Process finished with exit code 0
*/
```
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]