while(System.currentTimeMillis() - start <= runtime){ StringBuffer sb = new StringBuffer(); List<String> data = new ArrayList<String>(); HttpURLConnection httpurlconnection = null; try{ URL url = new URL(this.reportAd); httpurlconnection = (HttpURLConnection) url.openConnection(); httpurlconnection.setConnectTimeout(5000); httpurlconnection.setReadTimeout(5000); httpurlconnection.setDoOutput(true); httpurlconnection.setRequestMethod("POST"); httpurlconnection.setRequestProperty("Content-type", "text/plain"); for(long i=0; i<this.recordnum; i++){ 。。。。。。 s = Math.abs(R.nextLong())%102400000+1024; staticWriteSize += s; reporter.incrCounter("TestTool", "Write Size", s); staticWriteTime += (endTime - startTime); reporter.incrCounter("TestTool", "Write Time", endTime - startTime); 。。。。。。 }else{ 。。。。。。 reporter.incrCounter("TestTool", "Read Size", s); staticReadTime += (endTime - startTime); reporter.incrCounter("TestTool", "Read Time", endTime - startTime); 。。。。。。 } Pair p = value.get(R.nextInt(value.size())); 。。。。。。 staticCount++; } reporter.incrCounter("TestTool", "Record num", this.recordnum); reporter.setStatus("Record: "+staticCount+"("+staticWrite+"w, "+staticRead+"r), Write Size: " +staticWriteSize+", Write Time: "+staticWriteTime +", Read Size: "+staticReadSize+", Read Time: "+staticReadTime); httpurlconnection.getOutputStream().write(sb.toString().getBytes()); httpurlconnection.getOutputStream().flush(); httpurlconnection.getOutputStream().close(); int code = httpurlconnection.getResponseCode(); if(code != 200) { LOG.warn("send data to master server failed, code=" + code); } reporter.incrCounter("TestTool", "Http Post num", 1); map.staticPost.addAndGet(1); Thread.sleep(interval); } catch (Exception e) { map.staticPost.addAndGet(1); reporter.incrCounter("TestTool", e.getClass().toString(), 1); LOG.warn(e.getMessage(), e); } finally { if (httpurlconnection != null) { httpurlconnection.disconnect(); } } |