Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 17F98200C79 for ; Fri, 14 Apr 2017 01:18:49 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 169BB160B98; Thu, 13 Apr 2017 23:18:49 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 4223D160BAD for ; Fri, 14 Apr 2017 01:18:48 +0200 (CEST) Received: (qmail 41435 invoked by uid 500); 13 Apr 2017 23:18:47 -0000 Mailing-List: contact dev-help@geode.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@geode.apache.org Delivered-To: mailing list dev@geode.apache.org Received: (qmail 41419 invoked by uid 99); 13 Apr 2017 23:18:47 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 13 Apr 2017 23:18:47 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 12C0DDFE2C; Thu, 13 Apr 2017 23:18:47 +0000 (UTC) From: kirklund To: dev@geode.apache.org Reply-To: dev@geode.apache.org References: In-Reply-To: Subject: [GitHub] geode pull request #450: GEODE-2632: create ClientCachePutBench Content-Type: text/plain Message-Id: <20170413231847.12C0DDFE2C@git1-us-west.apache.org> Date: Thu, 13 Apr 2017 23:18:47 +0000 (UTC) archived-at: Thu, 13 Apr 2017 23:18:49 -0000 Github user kirklund commented on a diff in the pull request: https://github.com/apache/geode/pull/450#discussion_r111505951 --- Diff: geode-core/src/jmh/java/org/apache/geode/internal/cache/tier/sockets/command/ClientCachePutBench.java --- @@ -0,0 +1,199 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license + * agreements. See the NOTICE file distributed with this work for additional information regarding + * copyright ownership. The ASF 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 org.apache.geode.internal.cache.tier.sockets.command; + +import static java.lang.System.*; +import static java.util.concurrent.TimeUnit.*; +import static org.apache.commons.io.FileUtils.*; +import static org.apache.commons.lang.StringUtils.*; +import static org.apache.geode.cache.client.ClientRegionShortcut.*; +import static org.apache.geode.distributed.AbstractLauncher.Status.*; +import static org.apache.geode.distributed.ConfigurationProperties.*; +import static org.apache.geode.distributed.internal.DistributionConfig.*; +import static org.apache.geode.internal.AvailablePort.*; +import static org.apache.geode.test.dunit.NetworkUtils.*; +import static org.assertj.core.api.Assertions.*; +import static org.awaitility.Awaitility.*; + +import org.apache.geode.cache.Region; +import org.apache.geode.cache.client.ClientCache; +import org.apache.geode.cache.client.ClientCacheFactory; +import org.apache.geode.distributed.ServerLauncher; +import org.apache.geode.internal.process.ProcessStreamReader; +import org.junit.rules.TemporaryFolder; +import org.openjdk.jmh.annotations.Benchmark; +import org.openjdk.jmh.annotations.BenchmarkMode; +import org.openjdk.jmh.annotations.Fork; +import org.openjdk.jmh.annotations.Level; +import org.openjdk.jmh.annotations.Measurement; +import org.openjdk.jmh.annotations.Mode; +import org.openjdk.jmh.annotations.OutputTimeUnit; +import org.openjdk.jmh.annotations.Scope; +import org.openjdk.jmh.annotations.Setup; +import org.openjdk.jmh.annotations.State; +import org.openjdk.jmh.annotations.TearDown; +import org.openjdk.jmh.annotations.Warmup; + +import java.io.File; +import java.io.IOException; +import java.net.URL; +import java.util.ArrayList; +import java.util.List; +import java.util.Random; +import java.util.concurrent.TimeUnit; + +/** + * Benchmark that measures throughput of client performing puts to a loner server. + */ +@Measurement(iterations = 3, time = 3, timeUnit = MINUTES) +@Warmup(iterations = 3, time = 1, timeUnit = MINUTES) +@Fork(3) +@BenchmarkMode(Mode.Throughput) +@OutputTimeUnit(TimeUnit.SECONDS) +@State(Scope.Thread) +@SuppressWarnings("unused") +public class ClientCachePutBench { + + static final long PROCESS_READER_TIMEOUT = 60 * 1000; + static final String CLASS_NAME = ClientCachePutBench.class.getSimpleName(); + static final String PACKAGE_NAME = + replace(ClientCachePutBench.class.getPackage().getName(), ".", "/"); + static final String REGION_NAME = CLASS_NAME + "-region"; + static final String SERVER_XML_NAME = "/" + PACKAGE_NAME + "/" + CLASS_NAME + "-server.xml"; + + @State(Scope.Benchmark) + public static class ClientState { + + Random random; + Region region; + + private Process process; + private volatile ProcessStreamReader processOutReader; + private volatile ProcessStreamReader processErrReader; + + private int serverPort; + private ServerLauncher launcher; + private File serverDirectory; + private ClientCache clientCache; + + private TemporaryFolder temporaryFolder = new TemporaryFolder(); + + @Setup(Level.Trial) + public void startServer() throws Exception { + System.out.println("\n" + "[ClientCachePutBench] startServer"); + + this.random = new Random(nanoTime()); + + this.temporaryFolder.create(); + this.serverDirectory = this.temporaryFolder.getRoot(); + + startServerProcess(); + + try { + startProcessReaders(); + + ServerLauncher serverLauncher = new ServerLauncher.Builder() + .setWorkingDirectory(this.serverDirectory.getAbsolutePath()).build(); + + await("Starting server in " + this.serverDirectory).atMost(2, MINUTES) + .until(() -> assertThat(serverLauncher.status().getStatus()).isEqualTo(ONLINE)); + + this.clientCache = new ClientCacheFactory().set(LOG_LEVEL, "warn") + .addPoolServer(getIPLiteral(), this.serverPort).create(); + this.region = + this.clientCache.createClientRegionFactory(PROXY).create(REGION_NAME); + + } finally { + stopProcessReaders(); + } + } + + private void startServerProcess() throws IOException { + File destServerXml = copyXmlToServerDirectory(); + + this.serverPort = getRandomAvailablePort(SOCKET); + + List command = new ArrayList<>(); + command.add(new File(new File(getProperty("java.home"), "bin"), "java").getCanonicalPath()); + command.add("-D" + GEMFIRE_PREFIX + CACHE_XML_FILE + "=" + destServerXml.getAbsolutePath()); + command.add("-D" + GEMFIRE_PREFIX + MCAST_PORT + "=0"); + command.add("-D" + GEMFIRE_PREFIX + LOCATORS + "="); + command.add("-D" + GEMFIRE_PREFIX + LOG_LEVEL + "=warn"); + command.add("-cp"); + command.add(getProperty("java.class.path")); + command.add(ServerLauncher.class.getName()); + command.add(ServerLauncher.Command.START.getName()); + command.add("server1"); + command.add("--server-port=" + this.serverPort); + + System.out.println("[ClientCachePutBench] Launching server with command: " + command); + + this.process = new ProcessBuilder(command).directory(this.serverDirectory).start(); + } + + private File copyXmlToServerDirectory() throws IOException { + URL srcServerXml = getClass().getResource(SERVER_XML_NAME); + assertThat(srcServerXml).isNotNull(); + File destServerXml = new File(this.serverDirectory, SERVER_XML_NAME); + copyURLToFile(srcServerXml, destServerXml); + return destServerXml; + } + + private void startProcessReaders() { + this.processOutReader = + new ProcessStreamReader.Builder(this.process).inputStream(this.process.getInputStream()) + .inputListener((line) -> System.out.println("[ClientCachePutBench][stdout] " + line)) + .build().start(); + this.processErrReader = + new ProcessStreamReader.Builder(this.process).inputStream(this.process.getErrorStream()) + .inputListener((line) -> System.out.println("[ClientCachePutBench][stderr] " + line)) + .build().start(); + } + + private void stopProcessReaders() throws InterruptedException { + if (this.processOutReader != null) { + this.processOutReader.stop().join(PROCESS_READER_TIMEOUT); + } + if (this.processErrReader != null) { + this.processErrReader.stop().join(PROCESS_READER_TIMEOUT); + } + } + + @TearDown(Level.Trial) + public void stopServer() throws Exception { + System.out.println("\n" + "[ClientCachePutBench] stopServer"); + try { + this.clientCache.close(false); + new ServerLauncher.Builder().setWorkingDirectory(this.serverDirectory.getAbsolutePath()) + .build().stop(); + } finally { + if (this.process != null) { + this.process.destroyForcibly(); + } + this.temporaryFolder.delete(); + } + } + } + + @Benchmark + public String performPutFromClient(final ClientState state) throws Exception { + return state.region.put(createRandomString(state), createRandomString(state)); + } --- End diff -- I've pushed changes that reduce the overall runtime some and also moves generation of keys and values into setup. The end result seems to be no measurable difference. --- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastructure@apache.org or file a JIRA ticket with INFRA. ---