Skip to content

Commit

Permalink
Refactoring: clean up random config keys in code
Browse files Browse the repository at this point in the history
Summary:
Consolidate shared config keys into single file rather than
having them duplicated everywhere.

Also add separate linkstore and nodestore config keys in prepartiong
for future changes.

Convert string argument to enum

Test Plan: ant test

Reviewers: dhruba

Reviewed By: dhruba

CC: vamsi

Differential Revision: https://reviews.facebook.net/D4773
  • Loading branch information
Tim Armstrong committed Aug 21, 2012
1 parent a08fb64 commit e9ddab8
Show file tree
Hide file tree
Showing 14 changed files with 244 additions and 150 deletions.
5 changes: 3 additions & 2 deletions config/LinkConfigMysql.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
# #
#################################

# driver to use for the test - can only take one value
store = com.facebook.LinkBench.LinkStoreMysql
# Implementation of LinkStore and NodeStore to use
linkstore = com.facebook.LinkBench.LinkStoreMysql
nodestore = com.facebook.LinkBench.LinkStoreMysql

# mysql configuration
host = yourhostname.here
Expand Down
72 changes: 72 additions & 0 deletions src/java/com/facebook/LinkBench/Config.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package com.facebook.LinkBench;

/**
* Consolidate shared config key strings in this file
* See sample config file for documentation of config properties
* @author tarmstrong
*
*/
public class Config {

public static final String DEBUGLEVEL = "debuglevel";

/* Control store implementations used */
public static final String LINKSTORE_CLASS = "linkstore";
public static final String NODESTORE_CLASS = "nodestore";

/* Schema and tables used */
public static final String DBID = "dbid";
public static final String LINK_TABLE = "linktable";
public static final String COUNT_TABLE = "counttable";
public static final String NODE_TABLE = "nodetable";

/* Control graph structure */
public static final String LOAD_RANDOM_SEED = "load_random_seed";
public static final String MIN_ID = "startid1";
public static final String MAX_ID = "maxid1";
public static final String RANDOM_ID2_MAX = "randomid2max";
public static final String NLINKS_FUNC = "nlinks_func";
public static final String NLINKS_CONFIG = "nlinks_config";
public static final String NLINKS_DEFAULT = "nlinks_default";
public static final String LINK_DATASIZE = "datasize";

/* Loading performance tuning */
public static final String NUM_LOADERS = "loaders";
public static final String LOADER_CHUNK_SIZE = "loader_chunk_size";

/* Request workload */
public static final String NUM_REQUESTERS = "requesters";
public static final String REQUEST_RANDOM_SEED = "request_random_seed";
public static final String READ_CONFIG = "read_config";
public static final String READ_FUNCTION = "read_function";
public static final String WRITE_CONFIG = "write_config";
public static final String WRITE_FUNCTION = "write_function";
public static final String PR_ADD_LINK = "addlink";
public static final String PR_DELETE_LINK = "deletelink";
public static final String PR_UPDATE_LINK = "updatelink";
public static final String PR_COUNT_LINKS = "countlink";
public static final String PR_GET_LINK = "getlink";
public static final String PR_GET_LINK_LIST = "getlinklist";
public static final String PR_ADD_NODE = "addnode";
public static final String PR_UPDATE_NODE = "updatenode";
public static final String PR_DELETE_NODE = "deletenode";
public static final String PR_GET_NODE = "getnode";
public static final String MAX_TIME = "maxtime";
public static final String REQUEST_RATE = "requestrate";
public static final String NUM_REQUESTS = "requests";
public static final String ID2GEN_CONFIG = "id2gen_config";

/* Statistics collection and reporting */
public static final String MAX_STAT_SAMPLES = "maxsamples";
public static final String DISPLAY_FREQ = "displayfreq";
public static final String MAPRED_REPORT_PROGRESS = "reportprogress";
public static final String PROGRESS_FREQ = "progressfreq";

/* MapReduce specific configuration */
public static final String TEMPDIR = "tempdir";
public static final String LOAD_DATA = "loaddata";
public static final String MAPRED_USE_INPUT_FILES = "useinputfiles";

/* External data */
public static final String DISTRIBUTION_DATA_FILE = "data_file";
}
2 changes: 1 addition & 1 deletion src/java/com/facebook/LinkBench/ConfigUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public static Level getDebugLevel(Properties props)
if (props == null) {
return Level.DEBUG;
}
String levStr = props.getProperty("debuglevel");
String levStr = props.getProperty(Config.DEBUGLEVEL);

if (levStr == null) {
return Level.DEBUG;
Expand Down
20 changes: 11 additions & 9 deletions src/java/com/facebook/LinkBench/LinkBenchDriver.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ private LinkStore initStore(Phase currentphase, int threadid)
LinkStore newstore = null;

if (store == null) {
store = props.getProperty("store");
store = props.getProperty(Config.LINKSTORE_CLASS);
logger.info("Using LinkStore implementation: " + store);
}

Expand Down Expand Up @@ -123,7 +123,7 @@ void load() throws IOException, InterruptedException, Throwable {

// load data

int nloaders = Integer.parseInt(props.getProperty("loaders"));
int nloaders = Integer.parseInt(props.getProperty(Config.NUM_LOADERS));
int nthreads = nloaders + 1;
List<LinkBenchLoad> loaders = new LinkedList<LinkBenchLoad>();
LinkBenchLatency latencyStats = new LinkBenchLatency(nthreads);
Expand All @@ -132,15 +132,15 @@ void load() throws IOException, InterruptedException, Throwable {
BlockingQueue<LoadChunk> chunk_q = new LinkedBlockingQueue<LoadChunk>();

// max id1 to generate
long maxid1 = Long.parseLong(props.getProperty("maxid1"));
long maxid1 = Long.parseLong(props.getProperty(Config.MAX_ID));
// id1 at which to start
long startid1 = Long.parseLong(props.getProperty("startid1"));
long startid1 = Long.parseLong(props.getProperty(Config.MIN_ID));

// Create loaders
logger.info("Starting loaders " + nloaders);
logger.debug("Bulk Load setting: " + bulkLoad);

Random masterRandom = createMasterRNG(props, "load_random_seed");
Random masterRandom = createMasterRNG(props, Config.LOAD_RANDOM_SEED);

LoadProgress loadTracker = new LoadProgress(logger, maxid1 - startid1);
for (int i = 0; i < nloaders; i++) {
Expand All @@ -159,7 +159,8 @@ void load() throws IOException, InterruptedException, Throwable {
long loadtime = concurrentExec(loaders);

// compute total #links loaded
int nlinks_default = Integer.parseInt(props.getProperty("nlinks_default"));
int nlinks_default = Integer.parseInt(props.getProperty(
Config.NLINKS_DEFAULT));

long expectedlinks = (1 + nlinks_default) * (maxid1 - startid1);

Expand Down Expand Up @@ -217,7 +218,7 @@ private void enqueueLoadWork(BlockingQueue<LoadChunk> chunk_q, long startid1,
// load balancing, since queue is FIFO and later chunks tend to be larger

int chunkSize = Integer.parseInt(
props.getProperty("loader_chunk_size", "2048"));
props.getProperty(Config.LOADER_CHUNK_SIZE, "2048"));
long chunk_num = 0;
ArrayList<LoadChunk> stack = new ArrayList<LoadChunk>();
for (long id1 = startid1; id1 < maxid1; id1 += chunkSize) {
Expand All @@ -244,7 +245,8 @@ void sendrequests() throws IOException, InterruptedException, Throwable {
}

// config info for requests
int nrequesters = Integer.parseInt(props.getProperty("requesters"));
int nrequesters = Integer.parseInt(props.getProperty(
Config.NUM_REQUESTERS));
if (nrequesters == 0) {
logger.info("NO REQUEST PHASE CONFIGURED. ");
return;
Expand All @@ -254,7 +256,7 @@ void sendrequests() throws IOException, InterruptedException, Throwable {

RequestProgress progress = LinkBenchRequest.createProgress(logger, props);

Random masterRandom = createMasterRNG(props, "request_random_seed");
Random masterRandom = createMasterRNG(props, Config.REQUEST_RANDOM_SEED);

// create requesters
for (int i = 0; i < nrequesters; i++) {
Expand Down
28 changes: 16 additions & 12 deletions src/java/com/facebook/LinkBench/LinkBenchDriverMR.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ private static LinkStore initStore(Phase currentphase,
LinkStore newstore = null;

if (store == null) {
store = props.getProperty("store");
store = props.getProperty(Config.LINKSTORE_CLASS);
logger.info("Using store class: " + store);
}

Expand Down Expand Up @@ -312,8 +312,8 @@ public void map(IntWritable loaderid,
LinkStore store = initStore(Phase.LOAD, loaderid.get());
LinkBenchLatency latencyStats = new LinkBenchLatency(nloaders.get());

long maxid1 = Long.parseLong(props.getProperty("maxid1"));
long startid1 = Long.parseLong(props.getProperty("startid1"));
long maxid1 = Long.parseLong(Config.MAX_ID);
long startid1 = Long.parseLong(Config.MIN_ID);

LoadProgress prog_tracker = new LoadProgress(
Logger.getLogger(ConfigUtil.LINKBENCH_LOGGER), maxid1 - startid1);
Expand Down Expand Up @@ -437,13 +437,14 @@ public void close() throws IOException {
* main route of the LOAD phase
*/
private void load() throws IOException, InterruptedException {
boolean loaddata = Boolean.parseBoolean(props.getProperty("loaddata"));
boolean loaddata = Boolean.parseBoolean(
props.getProperty(Config.LOAD_DATA));
if (!loaddata) {
logger.info("Skipping load data per the config");
return;
}

int nloaders = Integer.parseInt(props.getProperty("loaders"));
int nloaders = Integer.parseInt(props.getProperty(Config.NUM_LOADERS));
final JobConf jobconf = createJobConf(LOAD, nloaders);
FileSystem fs = setupInputFiles(jobconf, nloaders);

Expand All @@ -454,9 +455,10 @@ private void load() throws IOException, InterruptedException {
long loadtime = (System.currentTimeMillis() - starttime);

// compute total #links loaded
long maxid1 = Long.parseLong(props.getProperty("maxid1"));
long startid1 = Long.parseLong(props.getProperty("startid1"));
int nlinks_default = Integer.parseInt(props.getProperty("nlinks_default"));
long maxid1 = Long.parseLong(props.getProperty(Config.MAX_ID));
long startid1 = Long.parseLong(props.getProperty(Config.MIN_ID));
int nlinks_default = Integer.parseInt(
props.getProperty(Config.NLINKS_DEFAULT));
long expectedlinks = (1 + nlinks_default) * (maxid1 - startid1);
long actuallinks = readOutput(fs, jobconf);

Expand All @@ -474,7 +476,7 @@ private void load() throws IOException, InterruptedException {
*/
private void sendrequests() throws IOException, InterruptedException {
// config info for requests
int nrequesters = Integer.parseInt(props.getProperty("requesters"));
int nrequesters = Integer.parseInt(props.getProperty(Config.NUM_REQUESTERS));
final JobConf jobconf = createJobConf(REQUEST, nrequesters);
FileSystem fs = setupInputFiles(jobconf, nrequesters);

Expand Down Expand Up @@ -510,14 +512,16 @@ public int run(String[] args) throws Exception {
props.load(new FileInputStream(args[0]));

// get name or temporary directory
String tempdirname = props.getProperty("tempdir");
String tempdirname = props.getProperty(Config.TEMPDIR);
if (tempdirname != null) {
TMP_DIR = new Path(tempdirname);
}
// whether report progress through reporter
REPORT_PROGRESS = Boolean.parseBoolean(props.getProperty("reportprogress"));
REPORT_PROGRESS = Boolean.parseBoolean(
props.getProperty(Config.MAPRED_REPORT_PROGRESS));
// whether store mapper input in files
USE_INPUT_FILES = Boolean.parseBoolean(props.getProperty("useinputfiles"));
USE_INPUT_FILES = Boolean.parseBoolean(
props.getProperty(Config.MAPRED_USE_INPUT_FILES));

load();
sendrequests();
Expand Down
25 changes: 10 additions & 15 deletions src/java/com/facebook/LinkBench/LinkBenchLoad.java
Original file line number Diff line number Diff line change
Expand Up @@ -107,20 +107,20 @@ public LinkBenchLoad(LinkStore store,
/*
* Load settings from properties
*/
maxid1 = Long.parseLong(props.getProperty("maxid1"));
startid1 = Long.parseLong(props.getProperty("startid1"));
maxid1 = Long.parseLong(props.getProperty(Config.MAX_ID));
startid1 = Long.parseLong(props.getProperty(Config.MIN_ID));

// math functions may cause problems for id1 = 0. Start at 1.
if (startid1 <= 0) {
startid1 = 1;
}

debuglevel = ConfigUtil.getDebugLevel(props);
datasize = Integer.parseInt(props.getProperty("datasize"));
datasize = Integer.parseInt(props.getProperty(Config.LINK_DATASIZE));

nlinks_func = Integer.parseInt(props.getProperty("nlinks_func"));
nlinks_config = Integer.parseInt(props.getProperty("nlinks_config"));
nlinks_default = Integer.parseInt(props.getProperty("nlinks_default"));
nlinks_func = Integer.parseInt(props.getProperty(Config.NLINKS_FUNC));
nlinks_config = Integer.parseInt(props.getProperty(Config.NLINKS_CONFIG));
nlinks_default = Integer.parseInt(props.getProperty(Config.NLINKS_DEFAULT));
if (nlinks_func == -2) {//real distribution has it own initialization
try {
//load statistical data into RealDistribution
Expand All @@ -131,10 +131,10 @@ public LinkBenchLoad(LinkStore store,
}
}

displayfreq = Long.parseLong(props.getProperty("displayfreq"));
maxsamples = Integer.parseInt(props.getProperty("maxsamples"));
displayfreq = Long.parseLong(props.getProperty(Config.DISPLAY_FREQ));
maxsamples = Integer.parseInt(props.getProperty(Config.MAX_STAT_SAMPLES));

dbid = props.getProperty("dbid");
dbid = props.getProperty(Config.DBID);


/*
Expand All @@ -145,12 +145,7 @@ public LinkBenchLoad(LinkStore store,
diffShuffle = 0;
stats = new LinkBenchStats(loaderID, displayfreq, maxsamples);


/*
* Setup random number generators
*/
// random number generator for id2 if needed
randomid2max = Long.parseLong(props.getProperty("randomid2max"));
randomid2max = Long.parseLong(props.getProperty(Config.RANDOM_ID2_MAX));
}

public long getLinksLoaded() {
Expand Down
Loading

0 comments on commit e9ddab8

Please sign in to comment.