lyndonbauto commented on PR #2090:
URL: https://github.com/apache/tinkerpop/pull/2090#issuecomment-1587954864
@kenhuuu
> Hi Lyndon, is it possible for you to share what kind of testing you were
running that showed this issue?
Hey Ken, yeah sure, this isn't pretty code but here it is:
```
package com.aerospike.firefly.server;
import com.aerospike.firefly.Server;
import org.apache.tinkerpop.gremlin.driver.Cluster;
import org.apache.tinkerpop.gremlin.driver.remote.DriverRemoteConnection;
import
org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource;
import org.apache.tinkerpop.gremlin.structure.Property;
import org.junit.Test;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.Timer;
import java.util.TimerTask;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.stream.Collectors;
import static org.apache.tinkerpop.gremlin.driver.Tokens.ARGS_EVAL_TIMEOUT;
import static
org.apache.tinkerpop.gremlin.process.traversal.AnonymousTraversalSource.traversal;
public class TestServer {
private static final long SECOND = 1000;
private static final long MINUTE = 60 * SECOND;
private static final long TEST_DURATION = 4 * MINUTE;
private long totalExecuted = 0;
Server server;
@Test
public void testServer() throws Exception {
server = Server.main(new String[]
{"../conf/firefly-gremlin-server-local.yaml"});
HEAP_REPORTING_TIMER.schedule(new HeapReport(), 0, 5000);
exposeLeak();
}
private static final Timer HEAP_REPORTING_TIMER = new Timer(true);
private class HeapReport extends TimerTask {
@Override
public void run() {
System.gc();
System.gc();
System.gc();
System.out.printf("Heap size: %d MB%n",
Runtime.getRuntime().totalMemory() / 1024 / 1024);
System.out.printf("Executed %d queries%n", totalExecuted);
}
}
public void exposeLeak() throws Exception {
final long startTime = System.currentTimeMillis();
Cluster cluster =
Cluster.build().addContactPoint("localhost").port(8182).create();
DriverRemoteConnection drc = DriverRemoteConnection.using(cluster,
"g");
// final DriverRemoteConnection drc =
DriverRemoteConnection.using("localhost", 8182, "g");
final GraphTraversalSource g = traversal().withRemote(drc);
final ExecutorService executorService =
Executors.newFixedThreadPool(16);
g.with(ARGS_EVAL_TIMEOUT, 1L).V().drop().iterate();
for (int i = 0; i < 25000; i++) {
g.addV("randomVertex").
property("last_seen", String.format("%d",
System.currentTimeMillis())).
property("something", String.format("%d", i)).
property("otherThing", String.format("%d", i)).
property("anotherThing", String.format("%d", i)).
property("yetAnotherThing", String.format("%d", i)).
property("andAnotherThing", String.format("%d", i)).
property("andYetAnotherThing", String.format("%d", i)).
iterate();
}
final List ids = g.V().id().toList();
final List>> futures = new
ArrayList<>();
while (System.currentTimeMillis() - startTime <= TEST_DURATION) {
while (futures.size() > 500) {
Thread.sleep(100);
final List>>
completedFutures =
futures.stream().filter(Future::isDone).collect(Collectors.toList());
completedFutures.forEach(f -> {
try {
f.get();
} catch (Exception e) {
e.printStackTrace();
}
});
totalExecuted += completedFutures.size();
futures.removeAll(completedFutures);
}
final Random rand = new Random();
final List idz = new ArrayList<>();
for (int i = 0; i < 9; i++) {
idz.add(ids.get(rand.nextInt(ids.size(;
}
futures.add(executorService.submit(() ->
g.V(idz).properties("last_seen").toList()));
}
futures.forEach(f-> {
try {
f.get();
} catch (Exception e) {
e.printStackTrace();
}
});
drc.close();
Thread.sleep(3);
}
}
```
The server code is:
```
package com.aerospike.firefly;
import