forked from apavlo/h-store
-
Notifications
You must be signed in to change notification settings - Fork 0
/
inputclient
executable file
·144 lines (133 loc) · 5.44 KB
/
inputclient
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# -----------------------------------------------------------------------
# Copyright (C) 2012 by H-Store Project
# Brown University
# Massachusetts Institute of Technology
# Yale University
#
# http://hstore.cs.brown.edu/
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
# IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
# OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
# OTHER DEALINGS IN THE SOFTWARE.
# -----------------------------------------------------------------------
from __future__ import with_statement
import os
import sys
import subprocess
import logging
from glob import glob
## H-Store Third-Party Libraries
realpath = os.path.realpath(__file__)
basedir = os.path.dirname(realpath)
if not os.path.exists(realpath):
cwd = os.getcwd()
basename = os.path.basename(realpath)
if os.path.exists(os.path.join(cwd, basename)):
basedir = cwd
sys.path.append(os.path.realpath(os.path.join(basedir, "third_party/python")))
sys.path.append(os.path.realpath(os.path.join(basedir, "tools")))
import hstore
import argparse
logging.basicConfig(level = logging.INFO,
format="%(asctime)s %(levelname)-5s: %(message)s",
datefmt="%m-%d-%Y %H:%M:%S",
stream = sys.stdout)
THIRD_PARTY_DIR = "third_party/java/jars"
BUILD_DIR = "obj/release/prod"
BUILD_1_DIR = "obj/release/benchmarks"
JVM_ARGS = [
"-client",
"-Xmx2048m",
"-Dlog4j.configuration=log4j.properties",
"-ea",
]
JVM_CLASSPATH = [ BUILD_DIR ] + glob("%s/*.jar" % THIRD_PARTY_DIR)
JVM_TARGET = "edu.brown.stream.InputClient"
## ==============================================
## main
## ==============================================
if __name__ == '__main__':
aparser = argparse.ArgumentParser(description='S-Store Input Client')
aparser.add_argument('project', help='Benchmark name or Project Jar')
aparser.add_argument('--host', type=str,
help='Hostname of an HStoreSite to connect to.')
aparser.add_argument('--port', type=int,
help='Port number of an HStoreSite to connect to.')
aparser.add_argument('--file', type=str,
help='input file, default is word.txt.')
aparser.add_argument('--rate', type=int,
help='tuple sending rate.')
aparser.add_argument('--stop', type=bool,
help='stop after all tuple sends out or repeat again.')
aparser.add_argument('--json', type=str,
help='indicate if json result format should be printed out.')
aparser.add_argument('--display', type=str,
help='indicate if the terminal display the statistic result, otherwise, it will display the function result.')
aparser.add_argument('--interval', type=int,
help='batch time interval.')
aparser.add_argument('--rounds', type=int,
help='to indicate how batch rounds we need.')
args = vars(aparser.parse_args())
# Check whether we have a jar file
# Otherwise make sure it's a valid benchmarks
if not os.path.exists(args['project']):
benchmarks = hstore.getBenchmarks()
if not args['project'] in benchmarks:
logging.error("Invalid benchmark name '%s'" % args['project'])
logging.error("Valid benchmarks: %s" % ", ".join(benchmarks))
sys.exit(1)
args['project'] = "%s.jar" % args['project']
if not os.path.exists(args['project']):
logging.error("Project jar '%s' does not exist" % (args['project']))
sys.exit(1)
# Options
options = [ ]
for key in ('host', 'port'):
if key in args and args[key]:
options.append("terminal.%s=%s" % (key, args[key]))
## FOR
for key in ('file', 'rate', 'stop'):
if key in args and args[key]:
options.append("source.%s=%s" % (key, args[key]))
#end for
for key in ('interval', 'rounds'):
if key in args and args[key]:
options.append("batch.%s=%s" % (key, args[key]))
#end for
for key in ('json','display'):
if key in args and args[key]:
options.append("result.%s=%s" % (key, args[key]))
#end for
# Invoke java directly
cmd = "java %s -classpath %s %s catalog.jar=%s %s" % (\
" ".join(JVM_ARGS), \
":".join(JVM_CLASSPATH), \
JVM_TARGET, \
args['project'],
" ".join(options))
#logging.error(cmd)
logging.debug(cmd)
try:
p = subprocess.Popen(cmd, shell=True)
p.wait()
except:
pass
sys.exit(p.returncode)
## MAIN