All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.gemstone.gemfire.internal.tools.gfsh.app.commands.optional.perf Maven / Gradle / Ivy

The newest version!
/*
 * Copyright (c) 2010-2015 Pivotal Software, Inc. All rights reserved.
 *
 * Licensed 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. See accompanying
 * LICENSE file.
 */
package com.gemstone.gemfire.internal.tools.gfsh.app.commands.optional;

import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;

import com.gemstone.gemfire.cache.Region;
import com.gemstone.gemfire.internal.tools.gfsh.app.CommandExecutable;
import com.gemstone.gemfire.internal.tools.gfsh.app.Gfsh;

public class perf implements CommandExecutable
{
	private static final String HIDDEN_REGION_NAME_PREFIX = "_"; // 1 underscore
	
	private Gfsh gfsh;
//	Findbugs - unused fields
//	private Region localRegion;
//	private Iterator localRegionIterator;
//	private List localKeyList;
//	private int lastRowPrinted = 0;
	
	public perf(Gfsh gfsh)
	{
		this.gfsh = gfsh;
	}
	
	public void help()
	{
		gfsh.println("perf [-threads ]");
		gfsh.println("     [-payload ]");
		gfsh.println("     [-type put|get|delete|putall|getall|deleteall ]");
		gfsh.println("     [-input random|sequence");
		gfsh.println("     [-size ");
		gfsh.println("     [-key int|long|string|");
		gfsh.println("     [-loop ]");
		gfsh.println("     [-interval ]");
		gfsh.println("     []");
		gfsh.println("     [-?]");
		gfsh.println("     Measure throughput rates and \"put\" latency.");
		gfsh.println("     -threads  The number of threads to concurrently put data into");
		gfsh.println("         the fabric. Default: 1");
		gfsh.println("     -payload  The payliod size in bytes. Perf puts byte arrays of the");
		gfsh.println("         specified size into the fabric. Default: 100 bytes.");
		gfsh.println("     -type put|get|delete|putall|getall|deleteall ");
		gfsh.println("         The operation type.  is for '*all' only. Default: put");
		gfsh.println("     -input  The input type. 'random' selects keys randomly from the range of");
		gfsh.println("        . 'sequnce' sequntial keys from 1 to   The key type. The keys of the type");
		gfsh.println("         int or long are numerical values incremented in the loop. The keys");
		gfsh.println("         of type string are String values formed by the prefix and the numerical");
		gfsh.println("         values that are incremented in the loop. The default prefix is \"key\".");
		gfsh.println("         The keys of type  are supplied by the class that implements");
		gfsh.println("         the com.gemstone.gemfire.addons.gfsh.data.PerfKey interface. The class");
		gfsh.println("         implements getKey(int keyNum) which returns a Serializable or preferrably");
		gfsh.println("         DataSerializable object.");
		gfsh.println("     -loop   The number of iterations per thread. Each thread invokes");
		gfsh.println("         put() or putAll() per iteration. Default: 10000");
		gfsh.println("     -inteval  The display interval. Each thread prints the average");
		gfsh.println("         throughput and latency after each interval interation count. Default: 1000");
		gfsh.println("       The region to put data into. Default: current region.");
		gfsh.println("     Default: perf -threads 1 -payload 100 -type put -input random -size 10000 -loop 10000 -interval 1000 ./");
		
		gfsh.println();
	}
	
	public void execute(String command) throws Exception
	{
		if (command.startsWith("perf -?")) {
			help();
			return;
		} 
		
		perf(command);
	}
	
	private void perf(String command) throws Exception
	{
		LinkedList list = new LinkedList();
		gfsh.parseCommand(command, list);
		
		int threadCount = 1;
		int payloadSize = 100;
		int putAllSize = 1;
		int loopCount = 10000;
		int interval = 1000;
		String regionPath = null;
		
		int listSize = list.size();
		for (int i = 1; i < listSize; i++) {
			String arg = list.get(i);
			if (arg.equals("-threads")) {
				i++;
				if (i >= listSize) {
					gfsh.println("Error: '-threads' requires ");
					return;
				}
				threadCount = Integer.parseInt(list.get(i));
			} else if (arg.equals("-payload")) {
				i++;
				if (i >= listSize) {
					gfsh.println("Error: '-payload' requires ");
					return;
				}
				payloadSize = Integer.parseInt(list.get(i));
			} else if (arg.equals("-putall")) {
				i++;
				if (i >= listSize) {
					gfsh.println("Error: '-putall' requires ");
					return;
				}
				putAllSize = Integer.parseInt(list.get(i));
			} else if (arg.equals("-loop")) {
				i++;
				if (i >= listSize) {
					gfsh.println("Error: '-loop' requires ");
					return;
				}
				loopCount = Integer.parseInt(list.get(i));
			} else if (arg.equals("-interval")) {
				i++;
				if (i >= listSize) {
					gfsh.println("Error: '-interval' requires ");
					return;
				}
				interval = Integer.parseInt(list.get(i));
			} else {
				regionPath = list.get(i);
			}
		}
		if (regionPath == null) {
			regionPath = gfsh.getCurrentPath();
		}
		
		benchmark(threadCount, payloadSize, putAllSize, loopCount, interval, regionPath);
	}
	
	private void benchmark(int threadCount, 
			int payloadSize, 
			int putAllSize,
			int loopCount,
			int interval,
			String regionPath)
	{
		
	}
	
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy