http://git-wip-us.apache.org/repos/asf/hbase-site/blob/d70bb89e/testdevapidocs/src-html/org/apache/hadoop/hbase/PerformanceEvaluation.IncrementTest.html ---------------------------------------------------------------------- diff --git a/testdevapidocs/src-html/org/apache/hadoop/hbase/PerformanceEvaluation.IncrementTest.html b/testdevapidocs/src-html/org/apache/hadoop/hbase/PerformanceEvaluation.IncrementTest.html index 7cf23c4..3f8844b 100644 --- a/testdevapidocs/src-html/org/apache/hadoop/hbase/PerformanceEvaluation.IncrementTest.html +++ b/testdevapidocs/src-html/org/apache/hadoop/hbase/PerformanceEvaluation.IncrementTest.html @@ -147,2627 +147,2705 @@ <span class="sourceLineNo">139</span> }<a name="line.139"></a> <span class="sourceLineNo">140</span><a name="line.140"></a> <span class="sourceLineNo">141</span> public static final String TABLE_NAME = "TestTable";<a name="line.141"></a> -<span class="sourceLineNo">142</span> public static final byte[] FAMILY_NAME = Bytes.toBytes("info");<a name="line.142"></a> -<span class="sourceLineNo">143</span> public static final byte [] COLUMN_ZERO = Bytes.toBytes("" + 0);<a name="line.143"></a> -<span class="sourceLineNo">144</span> public static final int DEFAULT_VALUE_LENGTH = 1000;<a name="line.144"></a> -<span class="sourceLineNo">145</span> public static final int ROW_LENGTH = 26;<a name="line.145"></a> -<span class="sourceLineNo">146</span><a name="line.146"></a> -<span class="sourceLineNo">147</span> private static final int ONE_GB = 1024 * 1024 * 1000;<a name="line.147"></a> -<span class="sourceLineNo">148</span> private static final int DEFAULT_ROWS_PER_GB = ONE_GB / DEFAULT_VALUE_LENGTH;<a name="line.148"></a> -<span class="sourceLineNo">149</span> // TODO : should we make this configurable<a name="line.149"></a> -<span class="sourceLineNo">150</span> private static final int TAG_LENGTH = 256;<a name="line.150"></a> -<span class="sourceLineNo">151</span> private static final DecimalFormat FMT = new DecimalFormat("0.##");<a name="line.151"></a> -<span class="sourceLineNo">152</span> private static final MathContext CXT = MathContext.DECIMAL64;<a name="line.152"></a> -<span class="sourceLineNo">153</span> private static final BigDecimal MS_PER_SEC = BigDecimal.valueOf(1000);<a name="line.153"></a> -<span class="sourceLineNo">154</span> private static final BigDecimal BYTES_PER_MB = BigDecimal.valueOf(1024 * 1024);<a name="line.154"></a> -<span class="sourceLineNo">155</span> private static final TestOptions DEFAULT_OPTS = new TestOptions();<a name="line.155"></a> -<span class="sourceLineNo">156</span><a name="line.156"></a> -<span class="sourceLineNo">157</span> private static Map<String, CmdDescriptor> COMMANDS = new TreeMap<>();<a name="line.157"></a> -<span class="sourceLineNo">158</span> private static final Path PERF_EVAL_DIR = new Path("performance_evaluation");<a name="line.158"></a> -<span class="sourceLineNo">159</span><a name="line.159"></a> -<span class="sourceLineNo">160</span> static {<a name="line.160"></a> -<span class="sourceLineNo">161</span> addCommandDescriptor(AsyncRandomReadTest.class, "asyncRandomRead",<a name="line.161"></a> -<span class="sourceLineNo">162</span> "Run async random read test");<a name="line.162"></a> -<span class="sourceLineNo">163</span> addCommandDescriptor(AsyncRandomWriteTest.class, "asyncRandomWrite",<a name="line.163"></a> -<span class="sourceLineNo">164</span> "Run async random write test");<a name="line.164"></a> -<span class="sourceLineNo">165</span> addCommandDescriptor(AsyncSequentialReadTest.class, "asyncSequentialRead",<a name="line.165"></a> -<span class="sourceLineNo">166</span> "Run async sequential read test");<a name="line.166"></a> -<span class="sourceLineNo">167</span> addCommandDescriptor(AsyncSequentialWriteTest.class, "asyncSequentialWrite",<a name="line.167"></a> -<span class="sourceLineNo">168</span> "Run async sequential write test");<a name="line.168"></a> -<span class="sourceLineNo">169</span> addCommandDescriptor(AsyncScanTest.class, "asyncScan",<a name="line.169"></a> -<span class="sourceLineNo">170</span> "Run async scan test (read every row)");<a name="line.170"></a> -<span class="sourceLineNo">171</span> addCommandDescriptor(RandomReadTest.class, RANDOM_READ,<a name="line.171"></a> -<span class="sourceLineNo">172</span> "Run random read test");<a name="line.172"></a> -<span class="sourceLineNo">173</span> addCommandDescriptor(RandomSeekScanTest.class, RANDOM_SEEK_SCAN,<a name="line.173"></a> -<span class="sourceLineNo">174</span> "Run random seek and scan 100 test");<a name="line.174"></a> -<span class="sourceLineNo">175</span> addCommandDescriptor(RandomScanWithRange10Test.class, "scanRange10",<a name="line.175"></a> -<span class="sourceLineNo">176</span> "Run random seek scan with both start and stop row (max 10 rows)");<a name="line.176"></a> -<span class="sourceLineNo">177</span> addCommandDescriptor(RandomScanWithRange100Test.class, "scanRange100",<a name="line.177"></a> -<span class="sourceLineNo">178</span> "Run random seek scan with both start and stop row (max 100 rows)");<a name="line.178"></a> -<span class="sourceLineNo">179</span> addCommandDescriptor(RandomScanWithRange1000Test.class, "scanRange1000",<a name="line.179"></a> -<span class="sourceLineNo">180</span> "Run random seek scan with both start and stop row (max 1000 rows)");<a name="line.180"></a> -<span class="sourceLineNo">181</span> addCommandDescriptor(RandomScanWithRange10000Test.class, "scanRange10000",<a name="line.181"></a> -<span class="sourceLineNo">182</span> "Run random seek scan with both start and stop row (max 10000 rows)");<a name="line.182"></a> -<span class="sourceLineNo">183</span> addCommandDescriptor(RandomWriteTest.class, "randomWrite",<a name="line.183"></a> -<span class="sourceLineNo">184</span> "Run random write test");<a name="line.184"></a> -<span class="sourceLineNo">185</span> addCommandDescriptor(SequentialReadTest.class, "sequentialRead",<a name="line.185"></a> -<span class="sourceLineNo">186</span> "Run sequential read test");<a name="line.186"></a> -<span class="sourceLineNo">187</span> addCommandDescriptor(SequentialWriteTest.class, "sequentialWrite",<a name="line.187"></a> -<span class="sourceLineNo">188</span> "Run sequential write test");<a name="line.188"></a> -<span class="sourceLineNo">189</span> addCommandDescriptor(ScanTest.class, "scan",<a name="line.189"></a> -<span class="sourceLineNo">190</span> "Run scan test (read every row)");<a name="line.190"></a> -<span class="sourceLineNo">191</span> addCommandDescriptor(FilteredScanTest.class, "filterScan",<a name="line.191"></a> -<span class="sourceLineNo">192</span> "Run scan test using a filter to find a specific row based on it's value " +<a name="line.192"></a> -<span class="sourceLineNo">193</span> "(make sure to use --rows=20)");<a name="line.193"></a> -<span class="sourceLineNo">194</span> addCommandDescriptor(IncrementTest.class, "increment",<a name="line.194"></a> -<span class="sourceLineNo">195</span> "Increment on each row; clients overlap on keyspace so some concurrent operations");<a name="line.195"></a> -<span class="sourceLineNo">196</span> addCommandDescriptor(AppendTest.class, "append",<a name="line.196"></a> -<span class="sourceLineNo">197</span> "Append on each row; clients overlap on keyspace so some concurrent operations");<a name="line.197"></a> -<span class="sourceLineNo">198</span> addCommandDescriptor(CheckAndMutateTest.class, "checkAndMutate",<a name="line.198"></a> -<span class="sourceLineNo">199</span> "CheckAndMutate on each row; clients overlap on keyspace so some concurrent operations");<a name="line.199"></a> -<span class="sourceLineNo">200</span> addCommandDescriptor(CheckAndPutTest.class, "checkAndPut",<a name="line.200"></a> -<span class="sourceLineNo">201</span> "CheckAndPut on each row; clients overlap on keyspace so some concurrent operations");<a name="line.201"></a> -<span class="sourceLineNo">202</span> addCommandDescriptor(CheckAndDeleteTest.class, "checkAndDelete",<a name="line.202"></a> -<span class="sourceLineNo">203</span> "CheckAndDelete on each row; clients overlap on keyspace so some concurrent operations");<a name="line.203"></a> -<span class="sourceLineNo">204</span> }<a name="line.204"></a> -<span class="sourceLineNo">205</span><a name="line.205"></a> -<span class="sourceLineNo">206</span> /**<a name="line.206"></a> -<span class="sourceLineNo">207</span> * Enum for map metrics. Keep it out here rather than inside in the Map<a name="line.207"></a> -<span class="sourceLineNo">208</span> * inner-class so we can find associated properties.<a name="line.208"></a> -<span class="sourceLineNo">209</span> */<a name="line.209"></a> -<span class="sourceLineNo">210</span> protected static enum Counter {<a name="line.210"></a> -<span class="sourceLineNo">211</span> /** elapsed time */<a name="line.211"></a> -<span class="sourceLineNo">212</span> ELAPSED_TIME,<a name="line.212"></a> -<span class="sourceLineNo">213</span> /** number of rows */<a name="line.213"></a> -<span class="sourceLineNo">214</span> ROWS<a name="line.214"></a> -<span class="sourceLineNo">215</span> }<a name="line.215"></a> -<span class="sourceLineNo">216</span><a name="line.216"></a> -<span class="sourceLineNo">217</span> protected static class RunResult implements Comparable<RunResult> {<a name="line.217"></a> -<span class="sourceLineNo">218</span> public RunResult(long duration, Histogram hist) {<a name="line.218"></a> -<span class="sourceLineNo">219</span> this.duration = duration;<a name="line.219"></a> -<span class="sourceLineNo">220</span> this.hist = hist;<a name="line.220"></a> -<span class="sourceLineNo">221</span> }<a name="line.221"></a> -<span class="sourceLineNo">222</span><a name="line.222"></a> -<span class="sourceLineNo">223</span> public final long duration;<a name="line.223"></a> -<span class="sourceLineNo">224</span> public final Histogram hist;<a name="line.224"></a> -<span class="sourceLineNo">225</span><a name="line.225"></a> -<span class="sourceLineNo">226</span> @Override<a name="line.226"></a> -<span class="sourceLineNo">227</span> public String toString() {<a name="line.227"></a> -<span class="sourceLineNo">228</span> return Long.toString(duration);<a name="line.228"></a> -<span class="sourceLineNo">229</span> }<a name="line.229"></a> -<span class="sourceLineNo">230</span><a name="line.230"></a> -<span class="sourceLineNo">231</span> @Override public int compareTo(RunResult o) {<a name="line.231"></a> -<span class="sourceLineNo">232</span> return Long.compare(this.duration, o.duration);<a name="line.232"></a> -<span class="sourceLineNo">233</span> }<a name="line.233"></a> -<span class="sourceLineNo">234</span> }<a name="line.234"></a> -<span class="sourceLineNo">235</span><a name="line.235"></a> -<span class="sourceLineNo">236</span> /**<a name="line.236"></a> -<span class="sourceLineNo">237</span> * Constructor<a name="line.237"></a> -<span class="sourceLineNo">238</span> * @param conf Configuration object<a name="line.238"></a> -<span class="sourceLineNo">239</span> */<a name="line.239"></a> -<span class="sourceLineNo">240</span> public PerformanceEvaluation(final Configuration conf) {<a name="line.240"></a> -<span class="sourceLineNo">241</span> super(conf);<a name="line.241"></a> -<span class="sourceLineNo">242</span> }<a name="line.242"></a> -<span class="sourceLineNo">243</span><a name="line.243"></a> -<span class="sourceLineNo">244</span> protected static void addCommandDescriptor(Class<? extends TestBase> cmdClass,<a name="line.244"></a> -<span class="sourceLineNo">245</span> String name, String description) {<a name="line.245"></a> -<span class="sourceLineNo">246</span> CmdDescriptor cmdDescriptor = new CmdDescriptor(cmdClass, name, description);<a name="line.246"></a> -<span class="sourceLineNo">247</span> COMMANDS.put(name, cmdDescriptor);<a name="line.247"></a> -<span class="sourceLineNo">248</span> }<a name="line.248"></a> -<span class="sourceLineNo">249</span><a name="line.249"></a> -<span class="sourceLineNo">250</span> /**<a name="line.250"></a> -<span class="sourceLineNo">251</span> * Implementations can have their status set.<a name="line.251"></a> -<span class="sourceLineNo">252</span> */<a name="line.252"></a> -<span class="sourceLineNo">253</span> interface Status {<a name="line.253"></a> -<span class="sourceLineNo">254</span> /**<a name="line.254"></a> -<span class="sourceLineNo">255</span> * Sets status<a name="line.255"></a> -<span class="sourceLineNo">256</span> * @param msg status message<a name="line.256"></a> -<span class="sourceLineNo">257</span> * @throws IOException<a name="line.257"></a> -<span class="sourceLineNo">258</span> */<a name="line.258"></a> -<span class="sourceLineNo">259</span> void setStatus(final String msg) throws IOException;<a name="line.259"></a> -<span class="sourceLineNo">260</span> }<a name="line.260"></a> -<span class="sourceLineNo">261</span><a name="line.261"></a> -<span class="sourceLineNo">262</span> /**<a name="line.262"></a> -<span class="sourceLineNo">263</span> * MapReduce job that runs a performance evaluation client in each map task.<a name="line.263"></a> -<span class="sourceLineNo">264</span> */<a name="line.264"></a> -<span class="sourceLineNo">265</span> public static class EvaluationMapTask<a name="line.265"></a> -<span class="sourceLineNo">266</span> extends Mapper<LongWritable, Text, LongWritable, LongWritable> {<a name="line.266"></a> -<span class="sourceLineNo">267</span><a name="line.267"></a> -<span class="sourceLineNo">268</span> /** configuration parameter name that contains the command */<a name="line.268"></a> -<span class="sourceLineNo">269</span> public final static String CMD_KEY = "EvaluationMapTask.command";<a name="line.269"></a> -<span class="sourceLineNo">270</span> /** configuration parameter name that contains the PE impl */<a name="line.270"></a> -<span class="sourceLineNo">271</span> public static final String PE_KEY = "EvaluationMapTask.performanceEvalImpl";<a name="line.271"></a> -<span class="sourceLineNo">272</span><a name="line.272"></a> -<span class="sourceLineNo">273</span> private Class<? extends Test> cmd;<a name="line.273"></a> -<span class="sourceLineNo">274</span><a name="line.274"></a> -<span class="sourceLineNo">275</span> @Override<a name="line.275"></a> -<span class="sourceLineNo">276</span> protected void setup(Context context) throws IOException, InterruptedException {<a name="line.276"></a> -<span class="sourceLineNo">277</span> this.cmd = forName(context.getConfiguration().get(CMD_KEY), Test.class);<a name="line.277"></a> -<span class="sourceLineNo">278</span><a name="line.278"></a> -<span class="sourceLineNo">279</span> // this is required so that extensions of PE are instantiated within the<a name="line.279"></a> -<span class="sourceLineNo">280</span> // map reduce task...<a name="line.280"></a> -<span class="sourceLineNo">281</span> Class<? extends PerformanceEvaluation> peClass =<a name="line.281"></a> -<span class="sourceLineNo">282</span> forName(context.getConfiguration().get(PE_KEY), PerformanceEvaluation.class);<a name="line.282"></a> -<span class="sourceLineNo">283</span> try {<a name="line.283"></a> -<span class="sourceLineNo">284</span> peClass.getConstructor(Configuration.class).newInstance(context.getConfiguration());<a name="line.284"></a> -<span class="sourceLineNo">285</span> } catch (Exception e) {<a name="line.285"></a> -<span class="sourceLineNo">286</span> throw new IllegalStateException("Could not instantiate PE instance", e);<a name="line.286"></a> -<span class="sourceLineNo">287</span> }<a name="line.287"></a> -<span class="sourceLineNo">288</span> }<a name="line.288"></a> -<span class="sourceLineNo">289</span><a name="line.289"></a> -<span class="sourceLineNo">290</span> private <Type> Class<? extends Type> forName(String className, Class<Type> type) {<a name="line.290"></a> -<span class="sourceLineNo">291</span> try {<a name="line.291"></a> -<span class="sourceLineNo">292</span> return Class.forName(className).asSubclass(type);<a name="line.292"></a> -<span class="sourceLineNo">293</span> } catch (ClassNotFoundException e) {<a name="line.293"></a> -<span class="sourceLineNo">294</span> throw new IllegalStateException("Could not find class for name: " + className, e);<a name="line.294"></a> -<span class="sourceLineNo">295</span> }<a name="line.295"></a> -<span class="sourceLineNo">296</span> }<a name="line.296"></a> -<span class="sourceLineNo">297</span><a name="line.297"></a> -<span class="sourceLineNo">298</span> @Override<a name="line.298"></a> -<span class="sourceLineNo">299</span> protected void map(LongWritable key, Text value, final Context context)<a name="line.299"></a> -<span class="sourceLineNo">300</span> throws IOException, InterruptedException {<a name="line.300"></a> -<span class="sourceLineNo">301</span><a name="line.301"></a> -<span class="sourceLineNo">302</span> Status status = new Status() {<a name="line.302"></a> -<span class="sourceLineNo">303</span> @Override<a name="line.303"></a> -<span class="sourceLineNo">304</span> public void setStatus(String msg) {<a name="line.304"></a> -<span class="sourceLineNo">305</span> context.setStatus(msg);<a name="line.305"></a> -<span class="sourceLineNo">306</span> }<a name="line.306"></a> -<span class="sourceLineNo">307</span> };<a name="line.307"></a> -<span class="sourceLineNo">308</span><a name="line.308"></a> -<span class="sourceLineNo">309</span> ObjectMapper mapper = new ObjectMapper();<a name="line.309"></a> -<span class="sourceLineNo">310</span> TestOptions opts = mapper.readValue(value.toString(), TestOptions.class);<a name="line.310"></a> -<span class="sourceLineNo">311</span> Configuration conf = HBaseConfiguration.create(context.getConfiguration());<a name="line.311"></a> -<span class="sourceLineNo">312</span> final Connection con = ConnectionFactory.createConnection(conf);<a name="line.312"></a> -<span class="sourceLineNo">313</span> AsyncConnection asyncCon = null;<a name="line.313"></a> -<span class="sourceLineNo">314</span> try {<a name="line.314"></a> -<span class="sourceLineNo">315</span> asyncCon = ConnectionFactory.createAsyncConnection(conf).get();<a name="line.315"></a> -<span class="sourceLineNo">316</span> } catch (ExecutionException e) {<a name="line.316"></a> -<span class="sourceLineNo">317</span> throw new IOException(e);<a name="line.317"></a> -<span class="sourceLineNo">318</span> }<a name="line.318"></a> -<span class="sourceLineNo">319</span><a name="line.319"></a> -<span class="sourceLineNo">320</span> // Evaluation task<a name="line.320"></a> -<span class="sourceLineNo">321</span> RunResult result = PerformanceEvaluation.runOneClient(this.cmd, conf, con, asyncCon, opts, status);<a name="line.321"></a> -<span class="sourceLineNo">322</span> // Collect how much time the thing took. Report as map output and<a name="line.322"></a> -<span class="sourceLineNo">323</span> // to the ELAPSED_TIME counter.<a name="line.323"></a> -<span class="sourceLineNo">324</span> context.getCounter(Counter.ELAPSED_TIME).increment(result.duration);<a name="line.324"></a> -<span class="sourceLineNo">325</span> context.getCounter(Counter.ROWS).increment(opts.perClientRunRows);<a name="line.325"></a> -<span class="sourceLineNo">326</span> context.write(new LongWritable(opts.startRow), new LongWritable(result.duration));<a name="line.326"></a> -<span class="sourceLineNo">327</span> context.progress();<a name="line.327"></a> -<span class="sourceLineNo">328</span> }<a name="line.328"></a> -<span class="sourceLineNo">329</span> }<a name="line.329"></a> -<span class="sourceLineNo">330</span><a name="line.330"></a> -<span class="sourceLineNo">331</span> /*<a name="line.331"></a> -<span class="sourceLineNo">332</span> * If table does not already exist, create. Also create a table when<a name="line.332"></a> -<span class="sourceLineNo">333</span> * {@code opts.presplitRegions} is specified or when the existing table's<a name="line.333"></a> -<span class="sourceLineNo">334</span> * region replica count doesn't match {@code opts.replicas}.<a name="line.334"></a> -<span class="sourceLineNo">335</span> */<a name="line.335"></a> -<span class="sourceLineNo">336</span> static boolean checkTable(Admin admin, TestOptions opts) throws IOException {<a name="line.336"></a> -<span class="sourceLineNo">337</span> TableName tableName = TableName.valueOf(opts.tableName);<a name="line.337"></a> -<span class="sourceLineNo">338</span> boolean needsDelete = false, exists = admin.tableExists(tableName);<a name="line.338"></a> -<span class="sourceLineNo">339</span> boolean isReadCmd = opts.cmdName.toLowerCase(Locale.ROOT).contains("read")<a name="line.339"></a> -<span class="sourceLineNo">340</span> || opts.cmdName.toLowerCase(Locale.ROOT).contains("scan");<a name="line.340"></a> -<span class="sourceLineNo">341</span> if (!exists && isReadCmd) {<a name="line.341"></a> -<span class="sourceLineNo">342</span> throw new IllegalStateException(<a name="line.342"></a> -<span class="sourceLineNo">343</span> "Must specify an existing table for read commands. Run a write command first.");<a name="line.343"></a> -<span class="sourceLineNo">344</span> }<a name="line.344"></a> -<span class="sourceLineNo">345</span> HTableDescriptor desc =<a name="line.345"></a> -<span class="sourceLineNo">346</span> exists ? admin.getTableDescriptor(TableName.valueOf(opts.tableName)) : null;<a name="line.346"></a> -<span class="sourceLineNo">347</span> byte[][] splits = getSplits(opts);<a name="line.347"></a> -<span class="sourceLineNo">348</span><a name="line.348"></a> -<span class="sourceLineNo">349</span> // recreate the table when user has requested presplit or when existing<a name="line.349"></a> -<span class="sourceLineNo">350</span> // {RegionSplitPolicy,replica count} does not match requested.<a name="line.350"></a> -<span class="sourceLineNo">351</span> if ((exists && opts.presplitRegions != DEFAULT_OPTS.presplitRegions)<a name="line.351"></a> -<span class="sourceLineNo">352</span> || (!isReadCmd && desc != null &&<a name="line.352"></a> -<span class="sourceLineNo">353</span> !StringUtils.equals(desc.getRegionSplitPolicyClassName(), opts.splitPolicy))<a name="line.353"></a> -<span class="sourceLineNo">354</span> || (!isReadCmd && desc != null && desc.getRegionReplication() != opts.replicas)) {<a name="line.354"></a> -<span class="sourceLineNo">355</span> needsDelete = true;<a name="line.355"></a> -<span class="sourceLineNo">356</span> // wait, why did it delete my table?!?<a name="line.356"></a> -<span class="sourceLineNo">357</span> LOG.debug(MoreObjects.toStringHelper("needsDelete")<a name="line.357"></a> -<span class="sourceLineNo">358</span> .add("needsDelete", needsDelete)<a name="line.358"></a> -<span class="sourceLineNo">359</span> .add("isReadCmd", isReadCmd)<a name="line.359"></a> -<span class="sourceLineNo">360</span> .add("exists", exists)<a name="line.360"></a> -<span class="sourceLineNo">361</span> .add("desc", desc)<a name="line.361"></a> -<span class="sourceLineNo">362</span> .add("presplit", opts.presplitRegions)<a name="line.362"></a> -<span class="sourceLineNo">363</span> .add("splitPolicy", opts.splitPolicy)<a name="line.363"></a> -<span class="sourceLineNo">364</span> .add("replicas", opts.replicas)<a name="line.364"></a> -<span class="sourceLineNo">365</span> .toString());<a name="line.365"></a> -<span class="sourceLineNo">366</span> }<a name="line.366"></a> -<span class="sourceLineNo">367</span><a name="line.367"></a> -<span class="sourceLineNo">368</span> // remove an existing table<a name="line.368"></a> -<span class="sourceLineNo">369</span> if (needsDelete) {<a name="line.369"></a> -<span class="sourceLineNo">370</span> if (admin.isTableEnabled(tableName)) {<a name="line.370"></a> -<span class="sourceLineNo">371</span> admin.disableTable(tableName);<a name="line.371"></a> -<span class="sourceLineNo">372</span> }<a name="line.372"></a> -<span class="sourceLineNo">373</span> admin.deleteTable(tableName);<a name="line.373"></a> -<span class="sourceLineNo">374</span> }<a name="line.374"></a> -<span class="sourceLineNo">375</span><a name="line.375"></a> -<span class="sourceLineNo">376</span> // table creation is necessary<a name="line.376"></a> -<span class="sourceLineNo">377</span> if (!exists || needsDelete) {<a name="line.377"></a> -<span class="sourceLineNo">378</span> desc = getTableDescriptor(opts);<a name="line.378"></a> -<span class="sourceLineNo">379</span> if (splits != null) {<a name="line.379"></a> -<span class="sourceLineNo">380</span> if (LOG.isDebugEnabled()) {<a name="line.380"></a> -<span class="sourceLineNo">381</span> for (int i = 0; i < splits.length; i++) {<a name="line.381"></a> -<span class="sourceLineNo">382</span> LOG.debug(" split " + i + ": " + Bytes.toStringBinary(splits[i]));<a name="line.382"></a> -<span class="sourceLineNo">383</span> }<a name="line.383"></a> -<span class="sourceLineNo">384</span> }<a name="line.384"></a> -<span class="sourceLineNo">385</span> }<a name="line.385"></a> -<span class="sourceLineNo">386</span> admin.createTable(desc, splits);<a name="line.386"></a> -<span class="sourceLineNo">387</span> LOG.info("Table " + desc + " created");<a name="line.387"></a> -<span class="sourceLineNo">388</span> }<a name="line.388"></a> -<span class="sourceLineNo">389</span> return admin.tableExists(tableName);<a name="line.389"></a> -<span class="sourceLineNo">390</span> }<a name="line.390"></a> -<span class="sourceLineNo">391</span><a name="line.391"></a> -<span class="sourceLineNo">392</span> /**<a name="line.392"></a> -<span class="sourceLineNo">393</span> * Create an HTableDescriptor from provided TestOptions.<a name="line.393"></a> -<span class="sourceLineNo">394</span> */<a name="line.394"></a> -<span class="sourceLineNo">395</span> protected static HTableDescriptor getTableDescriptor(TestOptions opts) {<a name="line.395"></a> -<span class="sourceLineNo">396</span> HTableDescriptor desc = new HTableDescriptor(TableName.valueOf(opts.tableName));<a name="line.396"></a> -<span class="sourceLineNo">397</span> HColumnDescriptor family = new HColumnDescriptor(FAMILY_NAME);<a name="line.397"></a> -<span class="sourceLineNo">398</span> family.setDataBlockEncoding(opts.blockEncoding);<a name="line.398"></a> -<span class="sourceLineNo">399</span> family.setCompressionType(opts.compression);<a name="line.399"></a> -<span class="sourceLineNo">400</span> family.setBloomFilterType(opts.bloomType);<a name="line.400"></a> -<span class="sourceLineNo">401</span> family.setBlocksize(opts.blockSize);<a name="line.401"></a> -<span class="sourceLineNo">402</span> if (opts.inMemoryCF) {<a name="line.402"></a> -<span class="sourceLineNo">403</span> family.setInMemory(true);<a name="line.403"></a> -<span class="sourceLineNo">404</span> }<a name="line.404"></a> -<span class="sourceLineNo">405</span> family.setInMemoryCompaction(opts.inMemoryCompaction);<a name="line.405"></a> -<span class="sourceLineNo">406</span> desc.addFamily(family);<a name="line.406"></a> -<span class="sourceLineNo">407</span> if (opts.replicas != DEFAULT_OPTS.replicas) {<a name="line.407"></a> -<span class="sourceLineNo">408</span> desc.setRegionReplication(opts.replicas);<a name="line.408"></a> -<span class="sourceLineNo">409</span> }<a name="line.409"></a> -<span class="sourceLineNo">410</span> if (opts.splitPolicy != null && !opts.splitPolicy.equals(DEFAULT_OPTS.splitPolicy)) {<a name="line.410"></a> -<span class="sourceLineNo">411</span> desc.setRegionSplitPolicyClassName(opts.splitPolicy);<a name="line.411"></a> -<span class="sourceLineNo">412</span> }<a name="line.412"></a> -<span class="sourceLineNo">413</span> return desc;<a name="line.413"></a> -<span class="sourceLineNo">414</span> }<a name="line.414"></a> -<span class="sourceLineNo">415</span><a name="line.415"></a> -<span class="sourceLineNo">416</span> /**<a name="line.416"></a> -<span class="sourceLineNo">417</span> * generates splits based on total number of rows and specified split regions<a name="line.417"></a> -<span class="sourceLineNo">418</span> */<a name="line.418"></a> -<span class="sourceLineNo">419</span> protected static byte[][] getSplits(TestOptions opts) {<a name="line.419"></a> -<span class="sourceLineNo">420</span> if (opts.presplitRegions == DEFAULT_OPTS.presplitRegions)<a name="line.420"></a> -<span class="sourceLineNo">421</span> return null;<a name="line.421"></a> +<span class="sourceLineNo">142</span> public static final String FAMILY_NAME_BASE = "info";<a name="line.142"></a> +<span class="sourceLineNo">143</span> public static final byte[] FAMILY_ZERO = Bytes.toBytes("info0");<a name="line.143"></a> +<span class="sourceLineNo">144</span> public static final byte[] COLUMN_ZERO = Bytes.toBytes("" + 0);<a name="line.144"></a> +<span class="sourceLineNo">145</span> public static final int DEFAULT_VALUE_LENGTH = 1000;<a name="line.145"></a> +<span class="sourceLineNo">146</span> public static final int ROW_LENGTH = 26;<a name="line.146"></a> +<span class="sourceLineNo">147</span><a name="line.147"></a> +<span class="sourceLineNo">148</span> private static final int ONE_GB = 1024 * 1024 * 1000;<a name="line.148"></a> +<span class="sourceLineNo">149</span> private static final int DEFAULT_ROWS_PER_GB = ONE_GB / DEFAULT_VALUE_LENGTH;<a name="line.149"></a> +<span class="sourceLineNo">150</span> // TODO : should we make this configurable<a name="line.150"></a> +<span class="sourceLineNo">151</span> private static final int TAG_LENGTH = 256;<a name="line.151"></a> +<span class="sourceLineNo">152</span> private static final DecimalFormat FMT = new DecimalFormat("0.##");<a name="line.152"></a> +<span class="sourceLineNo">153</span> private static final MathContext CXT = MathContext.DECIMAL64;<a name="line.153"></a> +<span class="sourceLineNo">154</span> private static final BigDecimal MS_PER_SEC = BigDecimal.valueOf(1000);<a name="line.154"></a> +<span class="sourceLineNo">155</span> private static final BigDecimal BYTES_PER_MB = BigDecimal.valueOf(1024 * 1024);<a name="line.155"></a> +<span class="sourceLineNo">156</span> private static final TestOptions DEFAULT_OPTS = new TestOptions();<a name="line.156"></a> +<span class="sourceLineNo">157</span><a name="line.157"></a> +<span class="sourceLineNo">158</span> private static Map<String, CmdDescriptor> COMMANDS = new TreeMap<>();<a name="line.158"></a> +<span class="sourceLineNo">159</span> private static final Path PERF_EVAL_DIR = new Path("performance_evaluation");<a name="line.159"></a> +<span class="sourceLineNo">160</span><a name="line.160"></a> +<span class="sourceLineNo">161</span> static {<a name="line.161"></a> +<span class="sourceLineNo">162</span> addCommandDescriptor(AsyncRandomReadTest.class, "asyncRandomRead",<a name="line.162"></a> +<span class="sourceLineNo">163</span> "Run async random read test");<a name="line.163"></a> +<span class="sourceLineNo">164</span> addCommandDescriptor(AsyncRandomWriteTest.class, "asyncRandomWrite",<a name="line.164"></a> +<span class="sourceLineNo">165</span> "Run async random write test");<a name="line.165"></a> +<span class="sourceLineNo">166</span> addCommandDescriptor(AsyncSequentialReadTest.class, "asyncSequentialRead",<a name="line.166"></a> +<span class="sourceLineNo">167</span> "Run async sequential read test");<a name="line.167"></a> +<span class="sourceLineNo">168</span> addCommandDescriptor(AsyncSequentialWriteTest.class, "asyncSequentialWrite",<a name="line.168"></a> +<span class="sourceLineNo">169</span> "Run async sequential write test");<a name="line.169"></a> +<span class="sourceLineNo">170</span> addCommandDescriptor(AsyncScanTest.class, "asyncScan",<a name="line.170"></a> +<span class="sourceLineNo">171</span> "Run async scan test (read every row)");<a name="line.171"></a> +<span class="sourceLineNo">172</span> addCommandDescriptor(RandomReadTest.class, RANDOM_READ,<a name="line.172"></a> +<span class="sourceLineNo">173</span> "Run random read test");<a name="line.173"></a> +<span class="sourceLineNo">174</span> addCommandDescriptor(RandomSeekScanTest.class, RANDOM_SEEK_SCAN,<a name="line.174"></a> +<span class="sourceLineNo">175</span> "Run random seek and scan 100 test");<a name="line.175"></a> +<span class="sourceLineNo">176</span> addCommandDescriptor(RandomScanWithRange10Test.class, "scanRange10",<a name="line.176"></a> +<span class="sourceLineNo">177</span> "Run random seek scan with both start and stop row (max 10 rows)");<a name="line.177"></a> +<span class="sourceLineNo">178</span> addCommandDescriptor(RandomScanWithRange100Test.class, "scanRange100",<a name="line.178"></a> +<span class="sourceLineNo">179</span> "Run random seek scan with both start and stop row (max 100 rows)");<a name="line.179"></a> +<span class="sourceLineNo">180</span> addCommandDescriptor(RandomScanWithRange1000Test.class, "scanRange1000",<a name="line.180"></a> +<span class="sourceLineNo">181</span> "Run random seek scan with both start and stop row (max 1000 rows)");<a name="line.181"></a> +<span class="sourceLineNo">182</span> addCommandDescriptor(RandomScanWithRange10000Test.class, "scanRange10000",<a name="line.182"></a> +<span class="sourceLineNo">183</span> "Run random seek scan with both start and stop row (max 10000 rows)");<a name="line.183"></a> +<span class="sourceLineNo">184</span> addCommandDescriptor(RandomWriteTest.class, "randomWrite",<a name="line.184"></a> +<span class="sourceLineNo">185</span> "Run random write test");<a name="line.185"></a> +<span class="sourceLineNo">186</span> addCommandDescriptor(SequentialReadTest.class, "sequentialRead",<a name="line.186"></a> +<span class="sourceLineNo">187</span> "Run sequential read test");<a name="line.187"></a> +<span class="sourceLineNo">188</span> addCommandDescriptor(SequentialWriteTest.class, "sequentialWrite",<a name="line.188"></a> +<span class="sourceLineNo">189</span> "Run sequential write test");<a name="line.189"></a> +<span class="sourceLineNo">190</span> addCommandDescriptor(ScanTest.class, "scan",<a name="line.190"></a> +<span class="sourceLineNo">191</span> "Run scan test (read every row)");<a name="line.191"></a> +<span class="sourceLineNo">192</span> addCommandDescriptor(FilteredScanTest.class, "filterScan",<a name="line.192"></a> +<span class="sourceLineNo">193</span> "Run scan test using a filter to find a specific row based on it's value " +<a name="line.193"></a> +<span class="sourceLineNo">194</span> "(make sure to use --rows=20)");<a name="line.194"></a> +<span class="sourceLineNo">195</span> addCommandDescriptor(IncrementTest.class, "increment",<a name="line.195"></a> +<span class="sourceLineNo">196</span> "Increment on each row; clients overlap on keyspace so some concurrent operations");<a name="line.196"></a> +<span class="sourceLineNo">197</span> addCommandDescriptor(AppendTest.class, "append",<a name="line.197"></a> +<span class="sourceLineNo">198</span> "Append on each row; clients overlap on keyspace so some concurrent operations");<a name="line.198"></a> +<span class="sourceLineNo">199</span> addCommandDescriptor(CheckAndMutateTest.class, "checkAndMutate",<a name="line.199"></a> +<span class="sourceLineNo">200</span> "CheckAndMutate on each row; clients overlap on keyspace so some concurrent operations");<a name="line.200"></a> +<span class="sourceLineNo">201</span> addCommandDescriptor(CheckAndPutTest.class, "checkAndPut",<a name="line.201"></a> +<span class="sourceLineNo">202</span> "CheckAndPut on each row; clients overlap on keyspace so some concurrent operations");<a name="line.202"></a> +<span class="sourceLineNo">203</span> addCommandDescriptor(CheckAndDeleteTest.class, "checkAndDelete",<a name="line.203"></a> +<span class="sourceLineNo">204</span> "CheckAndDelete on each row; clients overlap on keyspace so some concurrent operations");<a name="line.204"></a> +<span class="sourceLineNo">205</span> }<a name="line.205"></a> +<span class="sourceLineNo">206</span><a name="line.206"></a> +<span class="sourceLineNo">207</span> /**<a name="line.207"></a> +<span class="sourceLineNo">208</span> * Enum for map metrics. Keep it out here rather than inside in the Map<a name="line.208"></a> +<span class="sourceLineNo">209</span> * inner-class so we can find associated properties.<a name="line.209"></a> +<span class="sourceLineNo">210</span> */<a name="line.210"></a> +<span class="sourceLineNo">211</span> protected static enum Counter {<a name="line.211"></a> +<span class="sourceLineNo">212</span> /** elapsed time */<a name="line.212"></a> +<span class="sourceLineNo">213</span> ELAPSED_TIME,<a name="line.213"></a> +<span class="sourceLineNo">214</span> /** number of rows */<a name="line.214"></a> +<span class="sourceLineNo">215</span> ROWS<a name="line.215"></a> +<span class="sourceLineNo">216</span> }<a name="line.216"></a> +<span class="sourceLineNo">217</span><a name="line.217"></a> +<span class="sourceLineNo">218</span> protected static class RunResult implements Comparable<RunResult> {<a name="line.218"></a> +<span class="sourceLineNo">219</span> public RunResult(long duration, Histogram hist) {<a name="line.219"></a> +<span class="sourceLineNo">220</span> this.duration = duration;<a name="line.220"></a> +<span class="sourceLineNo">221</span> this.hist = hist;<a name="line.221"></a> +<span class="sourceLineNo">222</span> }<a name="line.222"></a> +<span class="sourceLineNo">223</span><a name="line.223"></a> +<span class="sourceLineNo">224</span> public final long duration;<a name="line.224"></a> +<span class="sourceLineNo">225</span> public final Histogram hist;<a name="line.225"></a> +<span class="sourceLineNo">226</span><a name="line.226"></a> +<span class="sourceLineNo">227</span> @Override<a name="line.227"></a> +<span class="sourceLineNo">228</span> public String toString() {<a name="line.228"></a> +<span class="sourceLineNo">229</span> return Long.toString(duration);<a name="line.229"></a> +<span class="sourceLineNo">230</span> }<a name="line.230"></a> +<span class="sourceLineNo">231</span><a name="line.231"></a> +<span class="sourceLineNo">232</span> @Override public int compareTo(RunResult o) {<a name="line.232"></a> +<span class="sourceLineNo">233</span> return Long.compare(this.duration, o.duration);<a name="line.233"></a> +<span class="sourceLineNo">234</span> }<a name="line.234"></a> +<span class="sourceLineNo">235</span> }<a name="line.235"></a> +<span class="sourceLineNo">236</span><a name="line.236"></a> +<span class="sourceLineNo">237</span> /**<a name="line.237"></a> +<span class="sourceLineNo">238</span> * Constructor<a name="line.238"></a> +<span class="sourceLineNo">239</span> * @param conf Configuration object<a name="line.239"></a> +<span class="sourceLineNo">240</span> */<a name="line.240"></a> +<span class="sourceLineNo">241</span> public PerformanceEvaluation(final Configuration conf) {<a name="line.241"></a> +<span class="sourceLineNo">242</span> super(conf);<a name="line.242"></a> +<span class="sourceLineNo">243</span> }<a name="line.243"></a> +<span class="sourceLineNo">244</span><a name="line.244"></a> +<span class="sourceLineNo">245</span> protected static void addCommandDescriptor(Class<? extends TestBase> cmdClass,<a name="line.245"></a> +<span class="sourceLineNo">246</span> String name, String description) {<a name="line.246"></a> +<span class="sourceLineNo">247</span> CmdDescriptor cmdDescriptor = new CmdDescriptor(cmdClass, name, description);<a name="line.247"></a> +<span class="sourceLineNo">248</span> COMMANDS.put(name, cmdDescriptor);<a name="line.248"></a> +<span class="sourceLineNo">249</span> }<a name="line.249"></a> +<span class="sourceLineNo">250</span><a name="line.250"></a> +<span class="sourceLineNo">251</span> /**<a name="line.251"></a> +<span class="sourceLineNo">252</span> * Implementations can have their status set.<a name="line.252"></a> +<span class="sourceLineNo">253</span> */<a name="line.253"></a> +<span class="sourceLineNo">254</span> interface Status {<a name="line.254"></a> +<span class="sourceLineNo">255</span> /**<a name="line.255"></a> +<span class="sourceLineNo">256</span> * Sets status<a name="line.256"></a> +<span class="sourceLineNo">257</span> * @param msg status message<a name="line.257"></a> +<span class="sourceLineNo">258</span> * @throws IOException<a name="line.258"></a> +<span class="sourceLineNo">259</span> */<a name="line.259"></a> +<span class="sourceLineNo">260</span> void setStatus(final String msg) throws IOException;<a name="line.260"></a> +<span class="sourceLineNo">261</span> }<a name="line.261"></a> +<span class="sourceLineNo">262</span><a name="line.262"></a> +<span class="sourceLineNo">263</span> /**<a name="line.263"></a> +<span class="sourceLineNo">264</span> * MapReduce job that runs a performance evaluation client in each map task.<a name="line.264"></a> +<span class="sourceLineNo">265</span> */<a name="line.265"></a> +<span class="sourceLineNo">266</span> public static class EvaluationMapTask<a name="line.266"></a> +<span class="sourceLineNo">267</span> extends Mapper<LongWritable, Text, LongWritable, LongWritable> {<a name="line.267"></a> +<span class="sourceLineNo">268</span><a name="line.268"></a> +<span class="sourceLineNo">269</span> /** configuration parameter name that contains the command */<a name="line.269"></a> +<span class="sourceLineNo">270</span> public final static String CMD_KEY = "EvaluationMapTask.command";<a name="line.270"></a> +<span class="sourceLineNo">271</span> /** configuration parameter name that contains the PE impl */<a name="line.271"></a> +<span class="sourceLineNo">272</span> public static final String PE_KEY = "EvaluationMapTask.performanceEvalImpl";<a name="line.272"></a> +<span class="sourceLineNo">273</span><a name="line.273"></a> +<span class="sourceLineNo">274</span> private Class<? extends Test> cmd;<a name="line.274"></a> +<span class="sourceLineNo">275</span><a name="line.275"></a> +<span class="sourceLineNo">276</span> @Override<a name="line.276"></a> +<span class="sourceLineNo">277</span> protected void setup(Context context) throws IOException, InterruptedException {<a name="line.277"></a> +<span class="sourceLineNo">278</span> this.cmd = forName(context.getConfiguration().get(CMD_KEY), Test.class);<a name="line.278"></a> +<span class="sourceLineNo">279</span><a name="line.279"></a> +<span class="sourceLineNo">280</span> // this is required so that extensions of PE are instantiated within the<a name="line.280"></a> +<span class="sourceLineNo">281</span> // map reduce task...<a name="line.281"></a> +<span class="sourceLineNo">282</span> Class<? extends PerformanceEvaluation> peClass =<a name="line.282"></a> +<span class="sourceLineNo">283</span> forName(context.getConfiguration().get(PE_KEY), PerformanceEvaluation.class);<a name="line.283"></a> +<span class="sourceLineNo">284</span> try {<a name="line.284"></a> +<span class="sourceLineNo">285</span> peClass.getConstructor(Configuration.class).newInstance(context.getConfiguration());<a name="line.285"></a> +<span class="sourceLineNo">286</span> } catch (Exception e) {<a name="line.286"></a> +<span class="sourceLineNo">287</span> throw new IllegalStateException("Could not instantiate PE instance", e);<a name="line.287"></a> +<span class="sourceLineNo">288</span> }<a name="line.288"></a> +<span class="sourceLineNo">289</span> }<a name="line.289"></a> +<span class="sourceLineNo">290</span><a name="line.290"></a> +<span class="sourceLineNo">291</span> private <Type> Class<? extends Type> forName(String className, Class<Type> type) {<a name="line.291"></a> +<span class="sourceLineNo">292</span> try {<a name="line.292"></a> +<span class="sourceLineNo">293</span> return Class.forName(className).asSubclass(type);<a name="line.293"></a> +<span class="sourceLineNo">294</span> } catch (ClassNotFoundException e) {<a name="line.294"></a> +<span class="sourceLineNo">295</span> throw new IllegalStateException("Could not find class for name: " + className, e);<a name="line.295"></a> +<span class="sourceLineNo">296</span> }<a name="line.296"></a> +<span class="sourceLineNo">297</span> }<a name="line.297"></a> +<span class="sourceLineNo">298</span><a name="line.298"></a> +<span class="sourceLineNo">299</span> @Override<a name="line.299"></a> +<span class="sourceLineNo">300</span> protected void map(LongWritable key, Text value, final Context context)<a name="line.300"></a> +<span class="sourceLineNo">301</span> throws IOException, InterruptedException {<a name="line.301"></a> +<span class="sourceLineNo">302</span><a name="line.302"></a> +<span class="sourceLineNo">303</span> Status status = new Status() {<a name="line.303"></a> +<span class="sourceLineNo">304</span> @Override<a name="line.304"></a> +<span class="sourceLineNo">305</span> public void setStatus(String msg) {<a name="line.305"></a> +<span class="sourceLineNo">306</span> context.setStatus(msg);<a name="line.306"></a> +<span class="sourceLineNo">307</span> }<a name="line.307"></a> +<span class="sourceLineNo">308</span> };<a name="line.308"></a> +<span class="sourceLineNo">309</span><a name="line.309"></a> +<span class="sourceLineNo">310</span> ObjectMapper mapper = new ObjectMapper();<a name="line.310"></a> +<span class="sourceLineNo">311</span> TestOptions opts = mapper.readValue(value.toString(), TestOptions.class);<a name="line.311"></a> +<span class="sourceLineNo">312</span> Configuration conf = HBaseConfiguration.create(context.getConfiguration());<a name="line.312"></a> +<span class="sourceLineNo">313</span> final Connection con = ConnectionFactory.createConnection(conf);<a name="line.313"></a> +<span class="sourceLineNo">314</span> AsyncConnection asyncCon = null;<a name="line.314"></a> +<span class="sourceLineNo">315</span> try {<a name="line.315"></a> +<span class="sourceLineNo">316</span> asyncCon = ConnectionFactory.createAsyncConnection(conf).get();<a name="line.316"></a> +<span class="sourceLineNo">317</span> } catch (ExecutionException e) {<a name="line.317"></a> +<span class="sourceLineNo">318</span> throw new IOException(e);<a name="line.318"></a> +<span class="sourceLineNo">319</span> }<a name="line.319"></a> +<span class="sourceLineNo">320</span><a name="line.320"></a> +<span class="sourceLineNo">321</span> // Evaluation task<a name="line.321"></a> +<span class="sourceLineNo">322</span> RunResult result = PerformanceEvaluation.runOneClient(this.cmd, conf, con, asyncCon, opts, status);<a name="line.322"></a> +<span class="sourceLineNo">323</span> // Collect how much time the thing took. Report as map output and<a name="line.323"></a> +<span class="sourceLineNo">324</span> // to the ELAPSED_TIME counter.<a name="line.324"></a> +<span class="sourceLineNo">325</span> context.getCounter(Counter.ELAPSED_TIME).increment(result.duration);<a name="line.325"></a> +<span class="sourceLineNo">326</span> context.getCounter(Counter.ROWS).increment(opts.perClientRunRows);<a name="line.326"></a> +<span class="sourceLineNo">327</span> context.write(new LongWritable(opts.startRow), new LongWritable(result.duration));<a name="line.327"></a> +<span class="sourceLineNo">328</span> context.progress();<a name="line.328"></a> +<span class="sourceLineNo">329</span> }<a name="line.329"></a> +<span class="sourceLineNo">330</span> }<a name="line.330"></a> +<span class="sourceLineNo">331</span><a name="line.331"></a> +<span class="sourceLineNo">332</span> /*<a name="line.332"></a> +<span class="sourceLineNo">333</span> * If table does not already exist, create. Also create a table when<a name="line.333"></a> +<span class="sourceLineNo">334</span> * {@code opts.presplitRegions} is specified or when the existing table's<a name="line.334"></a> +<span class="sourceLineNo">335</span> * region replica count doesn't match {@code opts.replicas}.<a name="line.335"></a> +<span class="sourceLineNo">336</span> */<a name="line.336"></a> +<span class="sourceLineNo">337</span> static boolean checkTable(Admin admin, TestOptions opts) throws IOException {<a name="line.337"></a> +<span class="sourceLineNo">338</span> TableName tableName = TableName.valueOf(opts.tableName);<a name="line.338"></a> +<span class="sourceLineNo">339</span> boolean needsDelete = false, exists = admin.tableExists(tableName);<a name="line.339"></a> +<span class="sourceLineNo">340</span> boolean isReadCmd = opts.cmdName.toLowerCase(Locale.ROOT).contains("read")<a name="line.340"></a> +<span class="sourceLineNo">341</span> || opts.cmdName.toLowerCase(Locale.ROOT).contains("scan");<a name="line.341"></a> +<span class="sourceLineNo">342</span> if (!exists && isReadCmd) {<a name="line.342"></a> +<span class="sourceLineNo">343</span> throw new IllegalStateException(<a name="line.343"></a> +<span class="sourceLineNo">344</span> "Must specify an existing table for read commands. Run a write command first.");<a name="line.344"></a> +<span class="sourceLineNo">345</span> }<a name="line.345"></a> +<span class="sourceLineNo">346</span> HTableDescriptor desc =<a name="line.346"></a> +<span class="sourceLineNo">347</span> exists ? admin.getTableDescriptor(TableName.valueOf(opts.tableName)) : null;<a name="line.347"></a> +<span class="sourceLineNo">348</span> byte[][] splits = getSplits(opts);<a name="line.348"></a> +<span class="sourceLineNo">349</span><a name="line.349"></a> +<span class="sourceLineNo">350</span> // recreate the table when user has requested presplit or when existing<a name="line.350"></a> +<span class="sourceLineNo">351</span> // {RegionSplitPolicy,replica count} does not match requested, or when the<a name="line.351"></a> +<span class="sourceLineNo">352</span> // number of column families does not match requested.<a name="line.352"></a> +<span class="sourceLineNo">353</span> if ((exists && opts.presplitRegions != DEFAULT_OPTS.presplitRegions)<a name="line.353"></a> +<span class="sourceLineNo">354</span> || (!isReadCmd && desc != null &&<a name="line.354"></a> +<span class="sourceLineNo">355</span> !StringUtils.equals(desc.getRegionSplitPolicyClassName(), opts.splitPolicy))<a name="line.355"></a> +<span class="sourceLineNo">356</span> || (!isReadCmd && desc != null && desc.getRegionReplication() != opts.replicas)<a name="line.356"></a> +<span class="sourceLineNo">357</span> || (desc != null && desc.getColumnFamilyCount() != opts.families)) {<a name="line.357"></a> +<span class="sourceLineNo">358</span> needsDelete = true;<a name="line.358"></a> +<span class="sourceLineNo">359</span> // wait, why did it delete my table?!?<a name="line.359"></a> +<span class="sourceLineNo">360</span> LOG.debug(MoreObjects.toStringHelper("needsDelete")<a name="line.360"></a> +<span class="sourceLineNo">361</span> .add("needsDelete", needsDelete)<a name="line.361"></a> +<span class="sourceLineNo">362</span> .add("isReadCmd", isReadCmd)<a name="line.362"></a> +<span class="sourceLineNo">363</span> .add("exists", exists)<a name="line.363"></a> +<span class="sourceLineNo">364</span> .add("desc", desc)<a name="line.364"></a> +<span class="sourceLineNo">365</span> .add("presplit", opts.presplitRegions)<a name="line.365"></a> +<span class="sourceLineNo">366</span> .add("splitPolicy", opts.splitPolicy)<a name="line.366"></a> +<span class="sourceLineNo">367</span> .add("replicas", opts.replicas)<a name="line.367"></a> +<span class="sourceLineNo">368</span> .add("families", opts.families)<a name="line.368"></a> +<span class="sourceLineNo">369</span> .toString());<a name="line.369"></a> +<span class="sourceLineNo">370</span> }<a name="line.370"></a> +<span class="sourceLineNo">371</span><a name="line.371"></a> +<span class="sourceLineNo">372</span> // remove an existing table<a name="line.372"></a> +<span class="sourceLineNo">373</span> if (needsDelete) {<a name="line.373"></a> +<span class="sourceLineNo">374</span> if (admin.isTableEnabled(tableName)) {<a name="line.374"></a> +<span class="sourceLineNo">375</span> admin.disableTable(tableName);<a name="line.375"></a> +<span class="sourceLineNo">376</span> }<a name="line.376"></a> +<span class="sourceLineNo">377</span> admin.deleteTable(tableName);<a name="line.377"></a> +<span class="sourceLineNo">378</span> }<a name="line.378"></a> +<span class="sourceLineNo">379</span><a name="line.379"></a> +<span class="sourceLineNo">380</span> // table creation is necessary<a name="line.380"></a> +<span class="sourceLineNo">381</span> if (!exists || needsDelete) {<a name="line.381"></a> +<span class="sourceLineNo">382</span> desc = getTableDescriptor(opts);<a name="line.382"></a> +<span class="sourceLineNo">383</span> if (splits != null) {<a name="line.383"></a> +<span class="sourceLineNo">384</span> if (LOG.isDebugEnabled()) {<a name="line.384"></a> +<span class="sourceLineNo">385</span> for (int i = 0; i < splits.length; i++) {<a name="line.385"></a> +<span class="sourceLineNo">386</span> LOG.debug(" split " + i + ": " + Bytes.toStringBinary(splits[i]));<a name="line.386"></a> +<span class="sourceLineNo">387</span> }<a name="line.387"></a> +<span class="sourceLineNo">388</span> }<a name="line.388"></a> +<span class="sourceLineNo">389</span> }<a name="line.389"></a> +<span class="sourceLineNo">390</span> admin.createTable(desc, splits);<a name="line.390"></a> +<span class="sourceLineNo">391</span> LOG.info("Table " + desc + " created");<a name="line.391"></a> +<span class="sourceLineNo">392</span> }<a name="line.392"></a> +<span class="sourceLineNo">393</span> return admin.tableExists(tableName);<a name="line.393"></a> +<span class="sourceLineNo">394</span> }<a name="line.394"></a> +<span class="sourceLineNo">395</span><a name="line.395"></a> +<span class="sourceLineNo">396</span> /**<a name="line.396"></a> +<span class="sourceLineNo">397</span> * Create an HTableDescriptor from provided TestOptions.<a name="line.397"></a> +<span class="sourceLineNo">398</span> */<a name="line.398"></a> +<span class="sourceLineNo">399</span> protected static HTableDescriptor getTableDescriptor(TestOptions opts) {<a name="line.399"></a> +<span class="sourceLineNo">400</span> HTableDescriptor tableDesc = new HTableDescriptor(TableName.valueOf(opts.tableName));<a name="line.400"></a> +<span class="sourceLineNo">401</span> for (int family = 0; family < opts.families; family++) {<a name="line.401"></a> +<span class="sourceLineNo">402</span> byte[] familyName = Bytes.toBytes(FAMILY_NAME_BASE + family);<a name="line.402"></a> +<span class="sourceLineNo">403</span> HColumnDescriptor familyDesc = new HColumnDescriptor(familyName);<a name="line.403"></a> +<span class="sourceLineNo">404</span> familyDesc.setDataBlockEncoding(opts.blockEncoding);<a name="line.404"></a> +<span class="sourceLineNo">405</span> familyDesc.setCompressionType(opts.compression);<a name="line.405"></a> +<span class="sourceLineNo">406</span> familyDesc.setBloomFilterType(opts.bloomType);<a name="line.406"></a> +<span class="sourceLineNo">407</span> familyDesc.setBlocksize(opts.blockSize);<a name="line.407"></a> +<span class="sourceLineNo">408</span> if (opts.inMemoryCF) {<a name="line.408"></a> +<span class="sourceLineNo">409</span> familyDesc.setInMemory(true);<a name="line.409"></a> +<span class="sourceLineNo">410</span> }<a name="line.410"></a> +<span class="sourceLineNo">411</span> familyDesc.setInMemoryCompaction(opts.inMemoryCompaction);<a name="line.411"></a> +<span class="sourceLineNo">412</span> tableDesc.addFamily(familyDesc);<a name="line.412"></a> +<span class="sourceLineNo">413</span> }<a name="line.413"></a> +<span class="sourceLineNo">414</span> if (opts.replicas != DEFAULT_OPTS.replicas) {<a name="line.414"></a> +<span class="sourceLineNo">415</span> tableDesc.setRegionReplication(opts.replicas);<a name="line.415"></a> +<span class="sourceLineNo">416</span> }<a name="line.416"></a> +<span class="sourceLineNo">417</span> if (opts.splitPolicy != null && !opts.splitPolicy.equals(DEFAULT_OPTS.splitPolicy)) {<a name="line.417"></a> +<span class="sourceLineNo">418</span> tableDesc.setRegionSplitPolicyClassName(opts.splitPolicy);<a name="line.418"></a> +<span class="sourceLineNo">419</span> }<a name="line.419"></a> +<span class="sourceLineNo">420</span> return tableDesc;<a name="line.420"></a> +<span class="sourceLineNo">421</span> }<a name="line.421"></a> <span class="sourceLineNo">422</span><a name="line.422"></a> -<span class="sourceLineNo">423</span> int numSplitPoints = opts.presplitRegions - 1;<a name="line.423"></a> -<span class="sourceLineNo">424</span> byte[][] splits = new byte[numSplitPoints][];<a name="line.424"></a> -<span class="sourceLineNo">425</span> int jump = opts.totalRows / opts.presplitRegions;<a name="line.425"></a> -<span class="sourceLineNo">426</span> for (int i = 0; i < numSplitPoints; i++) {<a name="line.426"></a> -<span class="sourceLineNo">427</span> int rowkey = jump * (1 + i);<a name="line.427"></a> -<span class="sourceLineNo">428</span> splits[i] = format(rowkey);<a name="line.428"></a> -<span class="sourceLineNo">429</span> }<a name="line.429"></a> -<span class="sourceLineNo">430</span> return splits;<a name="line.430"></a> -<span class="sourceLineNo">431</span> }<a name="line.431"></a> -<span class="sourceLineNo">432</span><a name="line.432"></a> -<span class="sourceLineNo">433</span> /*<a name="line.433"></a> -<span class="sourceLineNo">434</span> * Run all clients in this vm each to its own thread.<a name="line.434"></a> -<span class="sourceLineNo">435</span> */<a name="line.435"></a> -<span class="sourceLineNo">436</span> static RunResult[] doLocalClients(final TestOptions opts, final Configuration conf)<a name="line.436"></a> -<span class="sourceLineNo">437</span> throws IOException, InterruptedException, ExecutionException {<a name="line.437"></a> -<span class="sourceLineNo">438</span> final Class<? extends TestBase> cmd = determineCommandClass(opts.cmdName);<a name="line.438"></a> -<span class="sourceLineNo">439</span> assert cmd != null;<a name="line.439"></a> -<span class="sourceLineNo">440</span> @SuppressWarnings("unchecked")<a name="line.440"></a> -<span class="sourceLineNo">441</span> Future<RunResult>[] threads = new Future[opts.numClientThreads];<a name="line.441"></a> -<span class="sourceLineNo">442</span> RunResult[] results = new RunResult[opts.numClientThreads];<a name="line.442"></a> -<span class="sourceLineNo">443</span> ExecutorService pool = Executors.newFixedThreadPool(opts.numClientThreads,<a name="line.443"></a> -<span class="sourceLineNo">444</span> new ThreadFactoryBuilder().setNameFormat("TestClient-%s").build());<a name="line.444"></a> -<span class="sourceLineNo">445</span> final Connection con = ConnectionFactory.createConnection(conf);<a name="line.445"></a> -<span class="sourceLineNo">446</span> final AsyncConnection asyncCon = ConnectionFactory.createAsyncConnection(conf).get();<a name="line.446"></a> -<span class="sourceLineNo">447</span> for (int i = 0; i < threads.length; i++) {<a name="line.447"></a> -<span class="sourceLineNo">448</span> final int index = i;<a name="line.448"></a> -<span class="sourceLineNo">449</span> threads[i] = pool.submit(new Callable<RunResult>() {<a name="line.449"></a> -<span class="sourceLineNo">450</span> @Override<a name="line.450"></a> -<span class="sourceLineNo">451</span> public RunResult call() throws Exception {<a name="line.451"></a> -<span class="sourceLineNo">452</span> TestOptions threadOpts = new TestOptions(opts);<a name="line.452"></a> -<span class="sourceLineNo">453</span> if (threadOpts.startRow == 0) threadOpts.startRow = index * threadOpts.perClientRunRows;<a name="line.453"></a> -<span class="sourceLineNo">454</span> RunResult run = runOneClient(cmd, conf, con, asyncCon, threadOpts, new Status() {<a name="line.454"></a> -<span class="sourceLineNo">455</span> @Override<a name="line.455"></a> -<span class="sourceLineNo">456</span> public void setStatus(final String msg) throws IOException {<a name="line.456"></a> -<span class="sourceLineNo">457</span> LOG.info(msg);<a name="line.457"></a> -<span class="sourceLineNo">458</span> }<a name="line.458"></a> -<span class="sourceLineNo">459</span> });<a name="line.459"></a> -<span class="sourceLineNo">460</span> LOG.info("Finished " + Thread.currentThread().getName() + " in " + run.duration +<a name="line.460"></a> -<span class="sourceLineNo">461</span> "ms over " + threadOpts.perClientRunRows + " rows");<a name="line.461"></a> -<span class="sourceLineNo">462</span> return run;<a name="line.462"></a> -<span class="sourceLineNo">463</span> }<a name="line.463"></a> -<span class="sourceLineNo">464</span> });<a name="line.464"></a> -<span class="sourceLineNo">465</span> }<a name="line.465"></a> -<span class="sourceLineNo">466</span> pool.shutdown();<a name="line.466"></a> -<span class="sourceLineNo">467</span><a name="line.467"></a> -<span class="sourceLineNo">468</span> for (int i = 0; i < threads.length; i++) {<a name="line.468"></a> -<span class="sourceLineNo">469</span> try {<a name="line.469"></a> -<span class="sourceLineNo">470</span> results[i] = threads[i].get();<a name="line.470"></a> -<span class="sourceLineNo">471</span> } catch (ExecutionException e) {<a name="line.471"></a> -<span class="sourceLineNo">472</span> throw new IOException(e.getCause());<a name="line.472"></a> -<span class="sourceLineNo">473</span> }<a name="line.473"></a> -<span class="sourceLineNo">474</span> }<a name="line.474"></a> -<span class="sourceLineNo">475</span> final String test = cmd.getSimpleName();<a name="line.475"></a> -<span class="sourceLineNo">476</span> LOG.info("[" + test + "] Summary of timings (ms): "<a name="line.476"></a> -<span class="sourceLineNo">477</span> + Arrays.toString(results));<a name="line.477"></a> -<span class="sourceLineNo">478</span> Arrays.sort(results);<a name="line.478"></a> -<span class="sourceLineNo">479</span> long total = 0;<a name="line.479"></a> -<span class="sourceLineNo">480</span> for (RunResult result : results) {<a name="line.480"></a> -<span class="sourceLineNo">481</span> total += result.duration;<a name="line.481"></a> -<span class="sourceLineNo">482</span> }<a name="line.482"></a> -<span class="sourceLineNo">483</span> LOG.info("[" + test + "]"<a name="line.483"></a> -<span class="sourceLineNo">484</span> + "\tMin: " + results[0] + "ms"<a name="line.484"></a> -<span class="sourceLineNo">485</span> + "\tMax: " + results[results.length - 1] + "ms"<a name="line.485"></a> -<span class="sourceLineNo">486</span> + "\tAvg: " + (total / results.length) + "ms");<a name="line.486"></a> -<span class="sourceLineNo">487</span><a name="line.487"></a> -<span class="sourceLineNo">488</span> con.close();<a name="line.488"></a> -<span class="sourceLineNo">489</span> asyncCon.close();<a name="line.489"></a> -<span class="sourceLineNo">490</span><a name="line.490"></a> -<span class="sourceLineNo">491</span> return results;<a name="line.491"></a> -<span class="sourceLineNo">492</span> }<a name="line.492"></a> -<span class="sourceLineNo">493</span><a name="line.493"></a> -<span class="sourceLineNo">494</span> /*<a name="line.494"></a> -<span class="sourceLineNo">495</span> * Run a mapreduce job. Run as many maps as asked-for clients.<a name="line.495"></a> -<span class="sourceLineNo">496</span> * Before we start up the job, write out an input file with instruction<a name="line.496"></a> -<span class="sourceLineNo">497</span> * per client regards which row they are to start on.<a name="line.497"></a> -<span class="sourceLineNo">498</span> * @param cmd Command to run.<a name="line.498"></a> -<span class="sourceLineNo">499</span> * @throws IOException<a name="line.499"></a> -<span class="sourceLineNo">500</span> */<a name="line.500"></a> -<span class="sourceLineNo">501</span> static Job doMapReduce(TestOptions opts, final Configuration conf)<a name="line.501"></a> -<span class="sourceLineNo">502</span> throws IOException, InterruptedException, ClassNotFoundException {<a name="line.502"></a> -<span class="sourceLineNo">503</span> final Class<? extends TestBase> cmd = determineCommandClass(opts.cmdName);<a name="line.503"></a> -<span class="sourceLineNo">504</span> assert cmd != null;<a name="line.504"></a> -<span class="sourceLineNo">505</span> Path inputDir = writeInputFile(conf, opts);<a name="line.505"></a> -<span class="sourceLineNo">506</span> conf.set(EvaluationMapTask.CMD_KEY, cmd.getName());<a name="line.506"></a> -<span class="sourceLineNo">507</span> conf.set(EvaluationMapTask.PE_KEY, PerformanceEvaluation.class.getName());<a name="line.507"></a> -<span class="sourceLineNo">508</span> Job job = Job.getInstance(conf);<a name="line.508"></a> -<span class="sourceLineNo">509</span> job.setJarByClass(PerformanceEvaluation.class);<a name="line.509"></a> -<span class="sourceLineNo">510</span> job.setJobName("HBase Performance Evaluation - " + opts.cmdName);<a name="line.510"></a> -<span class="sourceLineNo">511</span><a name="line.511"></a> -<span class="sourceLineNo">512</span> job.setInputFormatClass(NLineInputFormat.class);<a name="line.512"></a> -<span class="sourceLineNo">513</span> NLineInputFormat.setInputPaths(job, inputDir);<a name="line.513"></a> -<span class="sourceLineNo">514</span> // this is default, but be explicit about it just in case.<a name="line.514"></a> -<span class="sourceLineNo">515</span> NLineInputFormat.setNumLinesPerSplit(job, 1);<a name="line.515"></a> -<span class="sourceLineNo">516</span><a name="line.516"></a> -<span class="sourceLineNo">517</span> job.setOutputKeyClass(LongWritable.class);<a name="line.517"></a> -<span class="sourceLineNo">518</span> job.setOutputValueClass(LongWritable.class);<a name="line.518"></a> -<span class="sourceLineNo">519</span><a name="line.519"></a> -<span class="sourceLineNo">520</span> job.setMapperClass(EvaluationMapTask.class);<a name="line.520"></a> -<span class="sourceLineNo">521</span> job.setReducerClass(LongSumReducer.class);<a name="line.521"></a> -<span class="sourceLineNo">522</span><a name="line.522"></a> -<span class="sourceLineNo">523</span> job.setNumReduceTasks(1);<a name="line.523"></a> -<span class="sourceLineNo">524</span><a name="line.524"></a> -<span class="sourceLineNo">525</span> job.setOutputFormatClass(TextOutputFormat.class);<a name="line.525"></a> -<span class="sourceLineNo">526</span> TextOutputFormat.setOutputPath(job, new Path(inputDir.getParent(), "outputs"));<a name="line.526"></a> -<span class="sourceLineNo">527</span><a name="line.527"></a> -<span class="sourceLineNo">528</span> TableMapReduceUtil.addDependencyJars(job);<a name="line.528"></a> -<span class="sourceLineNo">529</span> TableMapReduceUtil.addDependencyJarsForClasses(job.getConfiguration(),<a name="line.529"></a> -<span class="sourceLineNo">530</span> Histogram.class, // yammer metrics<a name="line.530"></a> -<span class="sourceLineNo">531</span> ObjectMapper.class, // jackson-mapper-asl<a name="line.531"></a> -<span class="sourceLineNo">532</span> FilterAllFilter.class // hbase-server tests jar<a name="line.532"></a> -<span class="sourceLineNo">533</span> );<a name="line.533"></a> +<span class="sourceLineNo">423</span> /**<a name="line.423"></a> +<span class="sourceLineNo">424</span> * generates splits based on total number of rows and specified split regions<a name="line.424"></a> +<span class="sourceLineNo">425</span> */<a name="line.425"></a> +<span class="sourceLineNo">426</span> protected static byte[][] getSplits(TestOptions opts) {<a name="line.426"></a> +<span class="sourceLineNo">427</span> if (opts.presplitRegions == DEFAULT_OPTS.presplitRegions)<a name="line.427"></a> +<span class="sourceLineNo">428</span> return null;<a name="line.428"></a> +<span class="sourceLineNo">429</span><a name="line.429"></a> +<span class="sourceLineNo">430</span> int numSplitPoints = opts.presplitRegions - 1;<a name="line.430"></a> +<span class="sourceLineNo">431</span> byte[][] splits = new byte[numSplitPoints][];<a name="line.431"></a> +<span class="sourceLineNo">432</span> int jump = opts.totalRows / opts.presplitRegions;<a name="line.432"></a> +<span class="sourceLineNo">433</span> for (int i = 0; i < numSplitPoints; i++) {<a name="line.433"></a> +<span class="sourceLineNo">434</span> int rowkey = jump * (1 + i);<a name="line.434"></a> +<span class="sourceLineNo">435</span> splits[i] = format(rowkey);<a name="line.435"></a> +<span class="sourceLineNo">436</span> }<a name="line.436"></a> +<span class="sourceLineNo">437</span> return splits;<a name="line.437"></a> +<span class="sourceLineNo">438</span> }<a name="line.438"></a> +<span class="sourceLineNo">439</span><a name="line.439"></a> +<span class="sourceLineNo">440</span> /*<a name="line.440"></a> +<span class="sourceLineNo">441</span> * Run all clients in this vm each to its own thread.<a name="line.441"></a> +<span class="sourceLineNo">442</span> */<a name="line.442"></a> +<span class="sourceLineNo">443</span> static RunResult[] doLocalClients(final TestOptions opts, final Configuration conf)<a name="line.443"></a> +<span class="sourceLineNo">444</span> throws IOException, InterruptedException, ExecutionException {<a name="line.444"></a> +<span class="sourceLineNo">445</span> final Class<? extends TestBase> cmd = determineCommandClass(opts.cmdName);<a name="line.445"></a> +<span class="sourceLineNo">446</span> assert cmd != null;<a name="line.446"></a> +<span class="sourceLineNo">447</span> @SuppressWarnings("unchecked")<a name="line.447"></a> +<span class="sourceLineNo">448</span> Future<RunResult>[] threads = new Future[opts.numClientThreads];<a name="line.448"></a> +<span class="sourceLineNo">449</span> RunResult[] results = new RunResult[opts.numClientThreads];<a name="line.449"></a> +<span class="sourceLineNo">450</span> ExecutorService pool = Executors.newFixedThreadPool(opts.numClientThreads,<a name="line.450"></a> +<span class="sourceLineNo">451</span> new ThreadFactoryBuilder().setNameFormat("TestClient-%s").build());<a name="line.451"></a> +<span class="sourceLineNo">452</span> final Connection con = ConnectionFactory.createConnection(conf);<a name="line.452"></a> +<span class="sourceLineNo">453</span> final AsyncConnection asyncCon = ConnectionFactory.createAsyncConnection(conf).get();<a name="line.453"></a> +<span class="sourceLineNo">454</span> for (int i = 0; i < threads.length; i++) {<a name="line.454"></a> +<span class="sourceLineNo">455</span> final int index = i;<a name="line.455"></a> +<span class="sourceLineNo">456</span> threads[i] = pool.submit(new Callable<RunResult>() {<a name="line.456"></a> +<span class="sourceLineNo">457</span> @Override<a name="line.457"></a> +<span class="sourceLineNo">458</span> public RunResult call() throws Exception {<a name="line.458"></a> +<span class="sourceLineNo">459</span> TestOptions threadOpts = new TestOptions(opts);<a name="line.459"></a> +<span class="sourceLineNo">460</span> if (threadOpts.startRow == 0) threadOpts.startRow = index * threadOpts.perClientRunRows;<a name="line.460"></a> +<span class="sourceLineNo">461</span> RunResult run = runOneClient(cmd, conf, con, asyncCon, threadOpts, new Status() {<a name="line.461"></a> +<span class="sourceLineNo">462</span> @Override<a name="line.462"></a> +<span class="sourceLineNo">463</span> public void setStatus(final String msg) throws IOException {<a name="line.463"></a> +<span class="sourceLineNo">464</span> LOG.info(msg);<a name="line.464"></a> +<span class="sourceLineNo">465</span> }<a name="line.465"></a> +<span class="sourceLineNo">466</span> });<a name="line.466"></a> +<span class="sourceLineNo">467</span> LOG.info("Finished " + Thread.currentThread().getName() + " in " + run.duration +<a name="line.467"></a> +<span class="sourceLineNo">468</span> "ms over " + threadOpts.perClientRunRows + " rows");<a name="line.468"></a> +<span class="sourceLineNo">469</span> return run;<a name="line.469"></a> +<span class="sourceLineNo">470</span> }<a name="line.470"></a> +<span class="sourceLineNo">471</span> });<a name="line.471"></a> +<span class="sourceLineNo">472</span> }<a name="line.472"></a> +<span class="sourceLineNo">473</span> pool.shutdown();<a name="line.473"></a> +<span class="sourceLineNo">474</span><a name="line.474"></a> +<span class="sourceLineNo">475</span> for (int i = 0; i < threads.length; i++) {<a name="line.475"></a> +<span class="sourceLineNo">476</span> try {<a name="line.476"></a> +<span class="sourceLineNo">477</span> results[i] = threads[i].get();<a name="line.477"></a> +<span class="sourceLineNo">478</span> } catch (ExecutionException e) {<a name="line.478"></a> +<span class="sourceLineNo">479</span> throw new IOException(e.getCause());<a name="line.479"></a> +<span class="sourceLineNo">480</span> }<a name="line.480"></a> +<span class="sourceLineNo">481</span> }<a name="line.481"></a> +<span class="sourceLineNo">482</span> final String test = cmd.getSimpleName();<a name="line.482"></a> +<span class="sourceLineNo">483</span> LOG.info("[" + test + "] Summary of timings (ms): "<a name="line.483"></a> +<span class="sourceLineNo">484</span> + Arrays.toString(results));<a name="line.484"></a> +<span class="sourceLineNo">485</span> Arrays.sort(results);<a name="line.485"></a> +<span class="sourceLineNo">486</span> long total = 0;<a name="line.486"></a> +<span class="sourceLineNo">487</span> for (RunResult result : results) {<a name="line.487"></a> +<span class="sourceLineNo">488</span> total += result.duration;<a name="line.488"></a> +<span class="sourceLineNo">489</span> }<a name="line.489"></a> +<span class="sourceLineNo">490</span> LOG.info("[" + test + "]"<a name="line.490"></a> +<span class="sourceLineNo">491</span> + "\tMin: " + results[0] + "ms"<a name="line.491"></a> +<span class="sourceLineNo">492</span> + "\tMax: " + results[results.length - 1] + "ms"<a name="line.492"></a> +<span class="sourceLineNo">493</span> + "\tAvg: " + (total / results.length) + "ms");<a name="line.493"></a> +<span class="sourceLineNo">494</span><a name="line.494"></a> +<span class="sourceLineNo">495</span> con.close();<a name="line.495"></a> +<span class="sourceLineNo">496</span> asyncCon.close();<a name="line.496"></a> +<span class="sourceLineNo">497</span><a name="line.497"></a> +<span class="sourceLineNo">498</span> return results;<a name="line.498"></a> +<span class="sourceLineNo">499</span> }<a name="line.499"></a> +<span class="sourceLineNo">500</span><a name="line.500"></a> +<span class="sourceLineNo">501</span> /*<a name="line.501"></a> +<span class="sourceLineNo">502</span> * Run a mapreduce job. Run as many maps as asked-for clients.<a name="line.502"></a> +<span class="sourceLineNo">503</span> * Before we start up the job, write out an input file with instruction<a name="line.503"></a> +<span class="sourceLineNo">504</span> * per client regards which row they are to start on.<a name="line.504"></a> +<span class="sourceLineNo">505</span> * @param cmd Command to run.<a name="line.505"></a> +<span class="sourceLineNo">506</span> * @throws IOException<a name="line.506"></a> +<span class="sourceLineNo">507</span> */<a name="line.507"></a> +<span class="sourceLineNo">508</span> static Job doMapReduce(TestOptions opts, final Configuration conf)<a name="line.508"></a> +<span class="sourceLineNo">509</span> throws IOException, InterruptedException, ClassNotFoundException {<a name="line.509"></a> +<span class="sourceLineNo">510</span> final Class<? extends TestBase> cmd = determineCommandClass(opts.cmdName);<a name="line.510"></a> +<span class="sourceLineNo">511</span> assert cmd != null;<a name="line.511"></a> +<span class="sourceLineNo">512</span> Path inputDir = writeInputFile(conf, opts);<a name="line.512"></a> +<span class="sourceLineNo">513</span> conf.set(EvaluationMapTask.CMD_KEY, cmd.getName());<a name="line.513"></a> +<span class="sourceLineNo">514</span> conf.set(EvaluationMapTask.PE_KEY, PerformanceEvaluation.class.getName());<a name="line.514"></a> +<span class="sourceLineNo">515</span> Job job = Job.getInstance(conf);<a name="line.515"></a> +<span class="sourceLineNo">516</span> job.setJarByClass(PerformanceEvaluation.class);<a name="line.516"></a> +<span class="sourceLineNo">517</span> job.setJobName("HBase Performance Evaluation - " + opts.cmdName);<a name="line.517"></a> +<span class="sourceLineNo">518</span><a name="line.518"></a> +<span class="sourceLineNo">519</span> job.setInputFormatClass(NLineInputFormat.class);<a name="line.519"></a> +<span class="sourceLineNo">520</span> NLineInputFormat.setInputPaths(job, inputDir);<a name="line.520"></a> +<span class="sourceLineNo">521</span> // this is default, but be explicit about it just in case.<a name="line.521"></a> +<span class="sourceLineNo">522</span> NLineInputFormat.setNumLinesPerSplit(job, 1);<a name="line.522"></a> +<span class="sourceLineNo">523</span><a name="line.523"></a> +<span class="sourceLineNo">524</span> job.setOutputKeyClass(LongWritable.class);<a name="line.524"></a> +<span class="sourceLineNo">525</span> job.setOutputValueClass(LongWritable.class);<a name="line.525"></a> +<span class="sourceLineNo">526</span><a name="line.526"></a> +<span class="sourceLineNo">527</span> job.setMapperClass(EvaluationMapTask.class);<a name="line.527"></a> +<span class="sourceLineNo">528</span> job.setReducerClass(LongSumReducer.class);<a name="line.528"></a> +<span class="sourceLineNo">529</span><a name="line.529"></a> +<span class="sourceLineNo">530</span> job.setNumReduceTasks(1);<a name="line.530"></a> +<span class="sourceLineNo">531</span><a name="line.531"></a> +<span class="sourceLineNo">532</span> job.setOutputFormatClass(TextOutputFormat.class);<a name="line.532"></a> +<span class="sourceLineNo">533</span> TextOutputFormat.setOutputPath(job, new Path(inputDir.getParent(), "outputs"));<a name="line.533"></a> <span class="sourceLineNo">534</span><a name="line.534"></a> -<span class="sourceLineNo">535</span> TableMapReduceUtil.initCredentials(job);<a name="line.535"></a> -<span class="sourceLineNo">536</span><a name="line.536"></a> -<span class="sourceLineNo">537</span> job.waitForCompletion(true);<a name="line.537"></a> -<span class="sourceLineNo">538</span> return job;<a name="line.538"></a> -<span class="sourceLineNo">539</span> }<a name="line.539"></a> -<span class="sourceLineNo">540</span><a name="line.540"></a> -<span class="sourceLineNo">541</span> /**<a name="line.541"></a> -<span class="sourceLineNo">542</span> * Each client has one mapper to do the work, and client do the resulting count in a map task.<a name="line.542"></a> -<span class="sourceLineNo">543</span> */<a name="line.543"></a> -<span class="sourceLineNo">544</span><a name="line.544"></a> -<span class="sourceLineNo">545</span> static String JOB_INPUT_FILENAME = "input.txt";<a name="line.545"></a> -<span class="sourceLineNo">546</span><a name="line.546"></a> -<span class="sourceLineNo">547</span> /*<a name="line.547"></a> -<span class="sourceLineNo">548</span> * Write input file of offsets-per-client for the mapreduce job.<a name="line.548"></a> -<span class="sourceLineNo">549</span> * @param c Configuration<a name="line.549"></a> -<span class="sourceLineNo">550</span> * @return Directory that contains file written whose name is JOB_INPUT_FILENAME<a name="line.550"></a> -<span class="sourceLineNo">551</span> * @throws IOException<a name="line.551"></a> -<span class="sourceLineNo">552</span> */<a name="line.552"></a> -<span class="sourceLineNo">553</span> static Path writeInputFile(final Configuration c, final TestOptions opts) throws IOException {<a name="line.553"></a> -<span class="sourceLineNo">554</span> return writeInputFile(c, opts, new Path("."));<a name="line.554"></a> -<span class="sourceLineNo">555</span> }<a name="line.555"></a> -<span class="sourceLineNo">556</span><a name="line.556"></a> -<span class="sourceLineNo">557</span> static Path writeInputFile(final Configuration c, final TestOptions opts, final Path basedir)<a name="line.557"></a> -<span class="sourceLineNo">558</span> throws IOException {<a name="line.558"></a> -<span class="sourceLineNo">559</span> SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMddHHmmss");<a name="line.559"></a> -<span class="sourceLineNo">560</span> Path jobdir = new Path(new Path(basedir, PERF_EVAL_DIR), formatter.format(new Date()));<a name="line.560"></a> -<span class="sourceLineNo">561</span> Path inputDir = new Path(jobdir, "inputs");<a name="line.561"></a> -<span class="sourceLineNo">562</span><a name="line.562"></a> -<span class="sourceLineNo">563</span> FileSystem fs = FileSystem.get(c);<a name="line.563"></a> -<span class="sourceLineNo">564</span> fs.mkdirs(inputDir);<a name="line.564"></a> -<span class="sourceLineNo">565</span><a name="line.565"></a> -<span class="sourceLineNo">566</span> Path inputFile = new Path(inputDir, JOB_INPUT_FILENAME);<a name="line.566"></a> -<span class="sourceLineNo">567</span> PrintStream out = new PrintStream(fs.create(inputFile));<a name="line.567"></a> -<span class="sourceLineNo">568</span> // Make input random.<a name="line.568"></a> -<span class="sourceLineNo">569</span> Map<Integer, String> m = new TreeMap<>();<a name="line.569"></a> -<span class="sourceLineNo">570</span> Hash h = MurmurHash.getInstance();<a name="line.570"></a> -<span class="sourceLineNo">571</span> int perClientRows = (opts.totalRows / opts.numClientThreads);<a name="line.571"></a> -<span class="sourceLineNo">572</span> try {<a name="line.572"></a> -<span class="sourceLineNo">573</span> for (int j = 0; j < opts.numClientThreads; j++) {<a name="line.573"></a> -<span class="sourceLineNo">574</span> TestOptions next = new TestOptions(opts);<a name="line.574"></a> -<span class="sourceLineNo">575</span> next.startRow = j * perClientRows;<a name="line.575"></a> -<span class="sourceLineNo">576</span> next.perClientRunRows = perClientRows;<a name="line.576"></a> -<span class="sourceLineNo">577</span> String s = MAPPER.writeValueAsString(next);<a name="line.577"></a> -<span class="sourceLineNo">578</span> LOG.info("Client=" + j + ", input=" + s);<a name="line.578"></a> -<span class="sourceLineNo">579</span> byte[] b = Bytes.toBytes(s);<a name="line.579"></a> -<span class="sourceLineNo">580</span> int hash = h.hash(new ByteArrayHashKey(b, 0, b.length), -1);<a name="line.580"></a> -<span class="sourceLineNo">581</span> m.put(hash, s);<a name="line.581"></a> -<span class="sourceLineNo">582</span> }<a name="line.582"></a> -<span class="sourceLineNo">583</span> for (Map.Entry<Integer, String> e: m.entrySet()) {<a name="line.583"></a> -<span class="sourceLineNo">584</span> out.println(e.getValue());<a name="line.584"></a> -<span class="sourceLineNo">585</span> }<a name="line.585"></a> -<span class="sourceLineNo">586</span> } finally {<a name="line.586"></a> -<span class="sourceLineNo">587</span> out.close();<a name="line.587"></a> -<span class="sourceLineNo">588</span> }<a name="line.588"></a> -<span class="sourceLineNo">589</span> return inputDir;<a name="line.589"></a> -<span class="sourceLineNo">590</span> }<a name="line.590"></a> -<span class="sourceLineNo">591</span><a name="line.591"></a> -<span class="sourceLineNo">592</span> /**<a name="line.592"></a> -<span class="sourceLineNo">593</span> * Describes a command.<a name="line.593"></a> -<span class="sourceLineNo">594</span> */<a name="line.594"></a> -<span class="sourceLineNo">595</span> static class CmdDescriptor {<a name="line.595"></a> -<span class="sourceLineNo">596</span> private Class<? extends TestBase> cmdClass;<a name="line.596"></a> -<span class="sourceLineNo">597</span> private String name;<a name="line.597"></a> -<span class="sourceLineNo">598</span> private String description;<a name="line.598"></a> -<span class="sourceLineNo">599</span><a name="line.599"></a> -<span class="sourceLineNo">600</span> CmdDescriptor(Class<? extends TestBase> cmdClass, String name, String description) {<a name="line.600"></a> -<span class="sourceLineNo">601</span> this.cmdClass = cmdClass;<a name="line.601"></a> -<span class="sourceLineNo">602</span> this.name = name;<a name="line.602"></a> -<span class="sourceLineNo">603</span> this.description = description;<a name="line.603"></a> -<span class="sourceLineNo">604</span> }<a name="line.604"></a> -<span class="sourceLineNo">605</span><a name="line.605"></a> -<span class="sourceLineNo">606</span> public Class<? extends TestBase> getCmdClass() {<a name="line.606"></a> -<span class="sourceLineNo">607</span> return cmdClass;<a name="line.607"></a> -<span class="sourceLineNo">608</span> }<a name="line.608"></a> -<span class="sourceLineNo">609</span><a name="line.609"></a> -<span class="sourceLineNo">610</span> public String getName() {<a name="line.610"></a> -<span class="sourceLineNo">611</span> return name;<a name="line.611"></a> -<span class="sourceLineNo">612</span> }<a name="line.612"></a> -<span class="sourceLineNo">613</span><a name="line.613"></a> -<span class="sourceLineNo">614</span> public String getDescription() {<a name="line.614"></a> -<span class="sourceLineNo">615</span> return description;<a name="line.615"></a> -<span class="sourceLineNo">616</span> }<a name="line.616"></a> -<span class="sourceLineNo">617</span> }<a name="line.617"></a> -<span class="sourceLineNo">618</span><a name="line.618"></a> -<span class="sourceLineNo">619</span> /**<a name="line.619"></a> -<span class="sourceLineNo">620</span> * Wraps up options passed to {@link org.apache.hadoop.hbase.PerformanceEvaluation}.<a name="line.620"></a> -<span class="sourceLineNo">621</span> * This makes tracking all these arguments a little easier.<a name="line.621"></a> -<span class="sourceLineNo">622</span> * NOTE: ADDING AN OPTION, you need to add a data member, a getter/setter (to make JSON<a name="line.622"></a> -<span class="sourceLineNo">623</span> * serialization of this TestOptions class behave), and you need to add to the clone constructor<a name="line.623"></a> -<span class="sourceLineNo">624</span> * below copying your new option from the 'that' to the 'this'. Look for 'clone' below.<a name="line.624"></a> -<span class="sourceLineNo">625</span> */<a name="line.625"></a> -<span class="sourceLineNo">626</span> static class TestOptions {<a name="line.626"></a> -<span class="sourceLineNo">627</span>
<TRUNCATED>