chore: import upstream snapshot with attribution
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
{auto_gen_header}
|
||||
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<parent>
|
||||
<groupId>io.ray</groupId>
|
||||
<artifactId>ray-superpom</artifactId>
|
||||
<version>2.0.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>ray-performance-test</artifactId>
|
||||
<name>java performance test cases for ray</name>
|
||||
<description>java performance test cases for ray</description>
|
||||
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>io.ray</groupId>
|
||||
<artifactId>ray-api</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.ray</groupId>
|
||||
<artifactId>ray-runtime</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
{generated_bzl_deps}
|
||||
</dependencies>
|
||||
</project>
|
||||
@@ -0,0 +1,40 @@
|
||||
package io.ray.performancetest;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
public class Receiver {
|
||||
private int value = 0;
|
||||
|
||||
public Receiver() {}
|
||||
|
||||
public boolean ping() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public void noArgsNoReturn() {
|
||||
value += 1;
|
||||
}
|
||||
|
||||
public int noArgsHasReturn() {
|
||||
value += 1;
|
||||
return value;
|
||||
}
|
||||
|
||||
public void bytesNoReturn(byte[] data) {
|
||||
value += 1;
|
||||
}
|
||||
|
||||
public int bytesHasReturn(byte[] data) {
|
||||
value += 1;
|
||||
return value;
|
||||
}
|
||||
|
||||
public void byteBufferNoReturn(ByteBuffer data) {
|
||||
value += 1;
|
||||
}
|
||||
|
||||
public int byteBufferHasReturn(ByteBuffer data) {
|
||||
value += 1;
|
||||
return value;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,117 @@
|
||||
package io.ray.performancetest;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import io.ray.api.ActorHandle;
|
||||
import io.ray.api.ObjectRef;
|
||||
import io.ray.api.Ray;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class Source {
|
||||
private static final int BATCH_SIZE;
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(Source.class);
|
||||
|
||||
private final List<ActorHandle<Receiver>> receivers;
|
||||
|
||||
static {
|
||||
String batchSizeString = System.getenv().get("PERF_TEST_BATCH_SIZE");
|
||||
if (batchSizeString != null) {
|
||||
BATCH_SIZE = Integer.valueOf(batchSizeString);
|
||||
} else {
|
||||
BATCH_SIZE = 1000;
|
||||
}
|
||||
}
|
||||
|
||||
public Source(List<ActorHandle<Receiver>> receivers) {
|
||||
this.receivers = receivers;
|
||||
}
|
||||
|
||||
public boolean startTest(
|
||||
boolean hasReturn, boolean ignoreReturn, int argSize, boolean useDirectByteBuffer) {
|
||||
LOGGER.info("Source startTest");
|
||||
byte[] bytes = null;
|
||||
ByteBuffer buffer = null;
|
||||
if (argSize > 0) {
|
||||
bytes = new byte[argSize];
|
||||
new Random().nextBytes(bytes);
|
||||
buffer = ByteBuffer.wrap(bytes);
|
||||
} else {
|
||||
Preconditions.checkState(!useDirectByteBuffer);
|
||||
}
|
||||
|
||||
// Wait for actors to be created.
|
||||
for (ActorHandle<Receiver> receiver : receivers) {
|
||||
receiver.task(Receiver::ping).remote().get();
|
||||
}
|
||||
|
||||
LOGGER.info(
|
||||
"Started executing tasks, useDirectByteBuffer: {}, argSize: {}, has return: {}",
|
||||
useDirectByteBuffer,
|
||||
argSize,
|
||||
hasReturn);
|
||||
|
||||
List<List<ObjectRef<Integer>>> returnObjects = new ArrayList<>();
|
||||
returnObjects.add(new ArrayList<>());
|
||||
returnObjects.add(new ArrayList<>());
|
||||
|
||||
long startTime = System.currentTimeMillis();
|
||||
int numTasks = 0;
|
||||
long lastReport = 0;
|
||||
long totalTime = 0;
|
||||
long batchCount = 0;
|
||||
while (true) {
|
||||
numTasks++;
|
||||
boolean batchEnd = numTasks % BATCH_SIZE == 0;
|
||||
for (ActorHandle<Receiver> receiver : receivers) {
|
||||
if (hasReturn || batchEnd) {
|
||||
ObjectRef<Integer> returnObject;
|
||||
if (useDirectByteBuffer) {
|
||||
returnObject = receiver.task(Receiver::byteBufferHasReturn, buffer).remote();
|
||||
} else if (argSize > 0) {
|
||||
returnObject = receiver.task(Receiver::bytesHasReturn, bytes).remote();
|
||||
} else {
|
||||
returnObject = receiver.task(Receiver::noArgsHasReturn).remote();
|
||||
}
|
||||
returnObjects.get(1).add(returnObject);
|
||||
} else {
|
||||
if (useDirectByteBuffer) {
|
||||
receiver.task(Receiver::byteBufferNoReturn, buffer).remote();
|
||||
} else if (argSize > 0) {
|
||||
receiver.task(Receiver::bytesNoReturn, bytes).remote();
|
||||
} else {
|
||||
receiver.task(Receiver::noArgsNoReturn).remote();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (batchEnd) {
|
||||
batchCount++;
|
||||
long getBeginTs = System.currentTimeMillis();
|
||||
Ray.get(returnObjects.get(0));
|
||||
long rt = System.currentTimeMillis() - getBeginTs;
|
||||
totalTime += rt;
|
||||
returnObjects.set(0, returnObjects.get(1));
|
||||
returnObjects.set(1, new ArrayList<>());
|
||||
|
||||
long elapsedTime = System.currentTimeMillis() - startTime;
|
||||
if (elapsedTime / 60000 > lastReport) {
|
||||
lastReport = elapsedTime / 60000;
|
||||
LOGGER.info(
|
||||
"Finished executing {} tasks in {} ms, useDirectByteBuffer: {}, argSize: {}, "
|
||||
+ "has return: {}, avg get rt: {}",
|
||||
numTasks,
|
||||
elapsedTime,
|
||||
useDirectByteBuffer,
|
||||
argSize,
|
||||
hasReturn,
|
||||
totalTime / (float) batchCount);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+73
@@ -0,0 +1,73 @@
|
||||
package io.ray.performancetest.test;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import io.ray.api.ActorHandle;
|
||||
import io.ray.api.ObjectRef;
|
||||
import io.ray.api.Ray;
|
||||
import io.ray.performancetest.Receiver;
|
||||
import io.ray.performancetest.Source;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class ActorPerformanceTestBase {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(ActorPerformanceTestBase.class);
|
||||
|
||||
public static void run(
|
||||
String[] args,
|
||||
int[] layers,
|
||||
int[] actorsPerLayer,
|
||||
boolean hasReturn,
|
||||
boolean ignoreReturn,
|
||||
int argSize,
|
||||
boolean useDirectByteBuffer) {
|
||||
Ray.init();
|
||||
try {
|
||||
// TODO: Support more layers.
|
||||
Preconditions.checkState(layers.length == 2);
|
||||
Preconditions.checkState(actorsPerLayer.length == layers.length);
|
||||
for (int i = 0; i < layers.length; i++) {
|
||||
Preconditions.checkState(layers[i] > 0);
|
||||
Preconditions.checkState(actorsPerLayer[i] > 0);
|
||||
}
|
||||
|
||||
List<ActorHandle<Receiver>> receivers = new ArrayList<>();
|
||||
for (int i = 0; i < layers[1]; i++) {
|
||||
int nodeIndex = layers[0] + i;
|
||||
for (int j = 0; j < actorsPerLayer[1]; j++) {
|
||||
receivers.add(Ray.actor(Receiver::new).remote());
|
||||
}
|
||||
}
|
||||
|
||||
List<ActorHandle<Source>> sources = new ArrayList<>();
|
||||
for (int i = 0; i < layers[0]; i++) {
|
||||
int nodeIndex = i;
|
||||
for (int j = 0; j < actorsPerLayer[0]; j++) {
|
||||
sources.add(Ray.actor(Source::new, receivers).remote());
|
||||
}
|
||||
}
|
||||
|
||||
List<ObjectRef<Boolean>> results =
|
||||
sources.stream()
|
||||
.map(
|
||||
source ->
|
||||
source
|
||||
.task(
|
||||
Source::startTest,
|
||||
hasReturn,
|
||||
ignoreReturn,
|
||||
argSize,
|
||||
useDirectByteBuffer)
|
||||
.remote())
|
||||
.collect(Collectors.toList());
|
||||
|
||||
Ray.get(results);
|
||||
} catch (Throwable e) {
|
||||
LOGGER.error("Run test failed.", e);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
package io.ray.performancetest.test;
|
||||
|
||||
/**
|
||||
* 1-to-1 ray call, one receiving actor and one sending actor, test the throughput of the engine
|
||||
* itself.
|
||||
*/
|
||||
public class ActorPerformanceTestCase1 {
|
||||
|
||||
public static void main(String[] args) {
|
||||
final int[] layers = new int[] {1, 1};
|
||||
final int[] actorsPerLayer = new int[] {1, 1};
|
||||
final boolean hasReturn = false;
|
||||
final int argSize = 0;
|
||||
final boolean useDirectByteBuffer = false;
|
||||
final boolean ignoreReturn = false;
|
||||
ActorPerformanceTestBase.run(
|
||||
args, layers, actorsPerLayer, hasReturn, ignoreReturn, argSize, useDirectByteBuffer);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user