protected static String computeStats(long time, long msgs, int size) { double msgs_sec, throughput=0; msgs_sec=msgs / (time/1000.0); throughput=(msgs * size) / (time / 1000.0); return String.format("%,d msgs, %s received, time=%,d ms, msgs/sec=%,.2f, throughput=%s", msgs, Util.printBytes(msgs * size), time, msgs_sec, Util.printBytes(throughput)); }
public String toString() { if(buffer != null) return Util.printBytes(buffer.length); else if(exception != null) return exception.toString(); return "OK"; }
protected static String computeStats(long time, long msgs, int size) { StringBuilder sb=new StringBuilder(); double msgs_sec, throughput=0; msgs_sec=msgs / (time/1000.0); throughput=(msgs * size) / (time / 1000.0); sb.append(msgs).append(" msgs, "); sb.append(Util.printBytes(msgs * size)).append(" received"); sb.append(", time=").append(format.format(time)).append("ms"); sb.append(", rpcs/sec=").append(format.format(msgs_sec)); sb.append(", throughput=").append(Util.printBytes(throughput)); return sb.toString(); }
protected void handleData() { if(last_interval == 0) last_interval=System.currentTimeMillis(); total_received_msgs.increment(); long received_so_far=total_received_msgs.sum(); if(received_so_far % receive_log_interval == 0) { long curr_time=System.currentTimeMillis(); long diff=curr_time - last_interval; double msgs_sec=receive_log_interval / (diff / 1000.0); double throughput=msgs_sec * msg_size; last_interval=curr_time; System.out.println(String.format("-- received %d msgs %d ms, %.2f msgs/sec, %s / sec)", received_so_far, diff, msgs_sec, Util.printBytes(throughput))); } }
public String toString() { boolean is_file=Util.isFlagSet(flags, FILE); StringBuilder sb=new StringBuilder(); sb.append(getType()); if(is_file) sb.append(", len=" + Util.printBytes(length) + ", chunk_size=" + chunk_size); sb.append(", mod_time=" + new Date(modification_time)); return sb.toString(); }
public void setState(InputStream istream) throws Exception { total_received=0; int received=0; while(true) { byte[] buf=new byte[10000]; received=istream.read(buf); if(received < 0) break; if(delay > 0) Util.sleep(delay); total_received+=received; if(requester_fails) throw new Exception("booom - requester failed"); } stop=System.currentTimeMillis(); System.out.println("<-- received " + Util.printBytes(total_received) + " in " + (stop-start) + "ms"); }
public void receiveData(long value, byte[] buffer) { long diff=System.currentTimeMillis() - value; total_req_time+=diff; num_reqs++; long new_val=current_value.incrementAndGet(); total_bytes.addAndGet(buffer.length); if(print > 0 && new_val % print == 0) System.out.println("received " + current_value); if(new_val >= num_values) { stop=System.currentTimeMillis(); long total_time=stop - start; long msgs_per_sec=(long)(num_values / (total_time / 1000.0)); double throughput=total_bytes.get() / (total_time / 1000.0); System.out.println("\n-- received " + num_values + " messages in " + total_time + " ms (" + msgs_per_sec + " messages/sec, " + Util.printBytes(throughput) + " / sec)"); double time_per_req=(double)total_req_time / num_reqs; System.out.println("received " + num_reqs + " requests in " + total_req_time + " ms, " + time_per_req + " ms / req (only requests)\n"); started=false; if(exit_on_end) System.exit(0); } }
public void getState(OutputStream ostream) throws Exception { int frag_size=size / 10; long bytes=0; for(int i=0; i < 10; i++) { byte[] buf=new byte[frag_size]; ostream.write(buf); bytes+=buf.length; if(provider_fails) throw new Exception("booom - provider failed"); if(delay > 0) Util.sleep(delay); } int remaining=size - (10 * frag_size); if(remaining > 0) { byte[] buf=new byte[remaining]; ostream.write(buf); bytes+=buf.length; } System.out.println("--> wrote " + Util.printBytes(bytes)); }
protected void handleData(Address src, long seqno, boolean check_order) { Stats result=received_msgs.get(src); if(result == null) { result=new Stats(); Stats tmp=received_msgs.putIfAbsent(src,result); if(tmp != null) result=tmp; } result.addMessage(seqno, check_order); if(last_interval == 0) last_interval=System.currentTimeMillis(); long received_so_far=total_received_msgs.incrementAndGet(); if(received_so_far % receive_log_interval == 0) { long curr_time=System.currentTimeMillis(); long diff=curr_time - last_interval; double msgs_sec=receive_log_interval / (diff / 1000.0); double throughput=msgs_sec * msg_size; last_interval=curr_time; System.out.printf("-- received %,d msgs (%,d ms, %,.2f msgs/sec, %s /sec)\n", received_so_far, diff, msgs_sec, Util.printBytes(throughput)); } }
private static String print(File file, boolean details, int indent) { StringBuilder sb=new StringBuilder(); if(file.isDirectory()) { if(details) sb.append(indent(indent)); sb.append(file.getName()).append("/"); } else { if(details) sb.append(indent(indent)); sb.append(file.getName()); if(details) { sb.append(" " + Util.printBytes(file.length())); if(file instanceof GridFile) sb.append(", chunk_sise=" + ((GridFile)file).getChunkSize()); } } sb.append(details? '\n' : ' '); return sb.toString(); }
public void handleData(Address src, byte[] payload, long seqno, boolean check_order) { // 0 int length=payload.length; if(length == 0) return; Stats tmp_result=received_msgs.get(src); if(tmp_result == null) { tmp_result=new Stats(); Stats tmp=received_msgs.putIfAbsent(src,tmp_result); if(tmp != null) tmp_result=tmp; } tmp_result.addMessage(seqno,check_order); if(last_interval == 0) last_interval=System.currentTimeMillis(); long received_so_far=total_received_msgs.incrementAndGet(); if(received_so_far % receive_log_interval == 0) { long curr_time=System.currentTimeMillis(); long diff=curr_time - last_interval; double msgs_sec=receive_log_interval / (diff / 1000.0); double throughput=msgs_sec * msg_size; last_interval=curr_time; System.out.println("-- received " + received_so_far + " rpcs " + "(" + diff + " ms, " + format.format(msgs_sec) + " rpcs/sec, " + Util.printBytes(throughput) + "/sec)"); } }
public Object up(Message msg) { if(log.isTraceEnabled()) { long size=raw_buffer? msg.getLength() : msg.size(); if(size >= min_size) { StringBuilder sb=new StringBuilder(local_addr + ".up(): size of message buffer="); sb.append(Util.printBytes(size)).append(", " + numHeaders(msg) + " headers"); if(print_msg) sb.append(", headers=" + msg.printHeaders()); log.trace(sb); } } return up_prot.up(msg); }
public Object down(Message msg) { if(log.isTraceEnabled()) { long size=raw_buffer? msg.getLength() : msg.size(); if(size >= min_size) { StringBuilder sb=new StringBuilder(local_addr + ".down(): size of message buffer="); sb.append(Util.printBytes(size)).append(", " + numHeaders(msg) + " headers"); if(print_msg) sb.append(", headers=" + msg.printHeaders()); log.trace(sb); } } return down_prot.down(msg); }
public void up(MessageBatch batch) { if(log.isTraceEnabled()) { long size=raw_buffer? batch.length() : batch.totalSize(); if(size >= min_size) { StringBuilder sb=new StringBuilder(local_addr + ".up(): size of message batch="); sb.append(Util.printBytes(size)).append(", " + batch.size() + " messages, " + numHeaders(batch) + " headers"); log.trace(sb); } } up_prot.up(batch); }
public String toString() { return String.format("%s bytes left (queuing: %b, msg-queue size: %d, bytes: %s, enqueued: %d)", super.toString(), isQueuing(), getQueuedMessages(), Util.printBytes(getQueuedMessageSize()), num_queued.intValue()); }
protected void setBufferSize(DatagramSocket sock, int send_buf_size, int recv_buf_size) { try { sock.setSendBufferSize(send_buf_size); int actual_size=sock.getSendBufferSize(); if(actual_size < send_buf_size && log.isWarnEnabled()) { log.warn(Util.getMessage("IncorrectBufferSize"), "send", sock.getClass().getSimpleName(), Util.printBytes(send_buf_size), Util.printBytes(actual_size), "send", "net.core.wmem_max"); } } catch(Throwable ex) { log.warn(Util.getMessage("BufferSizeFailed"), "send", send_buf_size, sock, ex); } try { sock.setReceiveBufferSize(recv_buf_size); int actual_size=sock.getReceiveBufferSize(); if(actual_size < recv_buf_size && log.isWarnEnabled()) { log.warn(Util.getMessage("IncorrectBufferSize"), "receive", sock.getClass().getSimpleName(), Util.printBytes(recv_buf_size), Util.printBytes(actual_size), "receive", "net.core.rmem_max"); } } catch(Throwable ex) { log.warn(Util.getMessage("BufferSizeFailed"), "receive", recv_buf_size, sock, ex); } }
public String toString() { return String.format("%s bytes left (queuing: %b, msg-queue size: %d, bytes: %s, enqueued: %d)", super.toString(), isQueuing(), getQueuedMessages(), Util.printBytes(getQueuedMessageSize()), num_queued.intValue()); }
protected void handleStateChunk(Address sender, byte[] buffer, int offset, int length) { if(buffer == null || input_stream == null) return; try { if(log.isTraceEnabled()) log.trace("%s: received chunk of %s from %s",local_addr,Util.printBytes(length),sender); input_stream.write(buffer, offset, length); } catch(IOException e) { handleException(e); } }
protected void sendMessage(byte[] b, int off, int len) throws IOException { Message m=new Message(stateRequester).putHeader(id, new StateHeader(StateHeader.STATE_PART)); // we're copying the buffer passed from the state provider here: if a BufferedOutputStream is used, the // buffer (b) will always be the same and can be modified after it has been set in the message ! // Fix for https://issues.jboss.org/browse/JGRP-1598 byte[] data=new byte[len]; System.arraycopy(b, off, data, 0, len); // m.setBuffer(b, off, len); m.setBuffer(data); bytesWrittenCounter+=len; if(Thread.interrupted()) throw interrupted((int)bytesWrittenCounter); down_prot.down(m); if(log.isTraceEnabled()) log.trace("%s: sent chunk of %s to %s",local_addr,Util.printBytes(len),stateRequester); }
protected void getStateFromApplication(Address requester, Digest digest) { StateTransferInfo rsp=(StateTransferInfo)up_prot.up(new Event(Event.GET_APPLSTATE)); byte[] state=rsp.state; if(stats) { num_state_reqs.increment(); if(state != null) num_bytes_sent.add(state.length); avg_state_size=num_bytes_sent.doubleValue() / num_state_reqs.doubleValue(); } Message state_rsp=new Message(requester, state).putHeader(this.id, new StateHeader(StateHeader.STATE_RSP, digest)); log.trace("%s: sending state to %s (size=%s)", local_addr, state_rsp.getDest(), Util.printBytes(state != null? state.length : 0)); down_prot.down(state_rsp); }