/** * Optionally return a {@code NodeStatistics} for the given nodeid, if * response information exists for the given node. Returns an empty * {@code Optional} if the node was not found. */ public Optional<ComputedNodeStats> getNodeStatistics(final String nodeId) { final int clientNum = nodeIdToStats.size(); return Optional.ofNullable(nodeIdToStats.get(nodeId)).map(ns -> new ComputedNodeStats(clientNum, ns)); }
@Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { builder.startObject("adaptive_selection"); Set<String> allNodeIds = Sets.union(clientOutgoingConnections.keySet(), nodeComputedStats.keySet()); for (String nodeId : allNodeIds) { builder.startObject(nodeId); ResponseCollectorService.ComputedNodeStats stats = nodeComputedStats.get(nodeId); if (stats != null) { long outgoingSearches = clientOutgoingConnections.getOrDefault(nodeId, 0L); builder.field("outgoing_searches", outgoingSearches); builder.field("avg_queue_size", stats.queueSize); if (builder.humanReadable()) { builder.field("avg_service_time", new TimeValue((long) stats.serviceTime, TimeUnit.NANOSECONDS).toString()); } builder.field("avg_service_time_ns", (long) stats.serviceTime); if (builder.humanReadable()) { builder.field("avg_response_time", new TimeValue((long) stats.responseTime, TimeUnit.NANOSECONDS).toString()); } builder.field("avg_response_time_ns", (long) stats.responseTime); builder.field("rank", String.format(Locale.ROOT, "%.1f", stats.rank(outgoingSearches))); } builder.endObject(); } builder.endObject(); return builder; }
@Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { builder.startObject("adaptive_selection"); Set<String> allNodeIds = Sets.union(clientOutgoingConnections.keySet(), nodeComputedStats.keySet()); for (String nodeId : allNodeIds) { builder.startObject(nodeId); ResponseCollectorService.ComputedNodeStats stats = nodeComputedStats.get(nodeId); if (stats != null) { long outgoingSearches = clientOutgoingConnections.getOrDefault(nodeId, 0L); builder.field("outgoing_searches", outgoingSearches); builder.field("avg_queue_size", stats.queueSize); if (builder.humanReadable()) { builder.field("avg_service_time", new TimeValue((long) stats.serviceTime, TimeUnit.NANOSECONDS).toString()); } builder.field("avg_service_time_ns", (long) stats.serviceTime); if (builder.humanReadable()) { builder.field("avg_response_time", new TimeValue((long) stats.responseTime, TimeUnit.NANOSECONDS).toString()); } builder.field("avg_response_time_ns", (long) stats.responseTime); builder.field("rank", String.format(Locale.ROOT, "%.1f", stats.rank(outgoingSearches))); } builder.endObject(); } builder.endObject(); return builder; }
@Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { builder.startObject("adaptive_selection"); Set<String> allNodeIds = Sets.union(clientOutgoingConnections.keySet(), nodeComputedStats.keySet()); for (String nodeId : allNodeIds) { builder.startObject(nodeId); ResponseCollectorService.ComputedNodeStats stats = nodeComputedStats.get(nodeId); if (stats != null) { long outgoingSearches = clientOutgoingConnections.getOrDefault(nodeId, 0L); builder.field("outgoing_searches", outgoingSearches); builder.field("avg_queue_size", stats.queueSize); if (builder.humanReadable()) { builder.field("avg_service_time", new TimeValue((long) stats.serviceTime, TimeUnit.NANOSECONDS).toString()); } builder.field("avg_service_time_ns", (long) stats.serviceTime); if (builder.humanReadable()) { builder.field("avg_response_time", new TimeValue((long) stats.responseTime, TimeUnit.NANOSECONDS).toString()); } builder.field("avg_response_time_ns", (long) stats.responseTime); builder.field("rank", String.format(Locale.ROOT, "%.1f", stats.rank(outgoingSearches))); } builder.endObject(); } builder.endObject(); return builder; }
@Override public String toString() { StringBuilder sb = new StringBuilder("ComputedNodeStats["); sb.append(nodeId).append("]("); sb.append("nodes: ").append(clientNum); sb.append(", queue: ").append(queueSize); sb.append(", response time: ").append(String.format(Locale.ROOT, "%.1f", responseTime)); sb.append(", service time: ").append(String.format(Locale.ROOT, "%.1f", serviceTime)); sb.append(", rank: ").append(String.format(Locale.ROOT, "%.1f", rank(1))); sb.append(")"); return sb.toString(); } }
private static Map<String, Double> rankNodes(final Map<String, Optional<ResponseCollectorService.ComputedNodeStats>> nodeStats, final Map<String, Long> nodeSearchCounts) { final Map<String, Double> nodeRanks = new HashMap<>(nodeStats.size()); for (Map.Entry<String, Optional<ResponseCollectorService.ComputedNodeStats>> entry : nodeStats.entrySet()) { Optional<ResponseCollectorService.ComputedNodeStats> maybeStats = entry.getValue(); maybeStats.ifPresent(stats -> { final String nodeId = entry.getKey(); nodeRanks.put(nodeId, stats.rank(nodeSearchCounts.getOrDefault(nodeId, 1L))); }); } return nodeRanks; }
@Override public void writeTo(StreamOutput out) throws IOException { out.writeMap(this.clientOutgoingConnections, StreamOutput::writeString, StreamOutput::writeLong); out.writeMap(this.nodeComputedStats, StreamOutput::writeString, (stream, stats) -> stats.writeTo(stream)); }
@Override public String toString() { StringBuilder sb = new StringBuilder("ComputedNodeStats["); sb.append(nodeId).append("]("); sb.append("nodes: ").append(clientNum); sb.append(", queue: ").append(queueSize); sb.append(", response time: ").append(String.format(Locale.ROOT, "%.1f", responseTime)); sb.append(", service time: ").append(String.format(Locale.ROOT, "%.1f", serviceTime)); sb.append(", rank: ").append(String.format(Locale.ROOT, "%.1f", rank(1))); sb.append(")"); return sb.toString(); } }
/** * Optionally return a {@code NodeStatistics} for the given nodeid, if * response information exists for the given node. Returns an empty * {@code Optional} if the node was not found. */ public Optional<ComputedNodeStats> getNodeStatistics(final String nodeId) { final int clientNum = nodeIdToStats.size(); return Optional.ofNullable(nodeIdToStats.get(nodeId)).map(ns -> new ComputedNodeStats(clientNum, ns)); }
/** * Returns a map of node id to the ranking of the nodes based on the adaptive replica formula */ public Map<String, Double> getRanks() { return nodeComputedStats.entrySet().stream() .collect(Collectors.toMap(Map.Entry::getKey, e -> e.getValue().rank(clientOutgoingConnections.getOrDefault(e.getKey(), 0L)))); } }
/** * Returns a map of node id to the ranking of the nodes based on the adaptive replica formula */ public Map<String, Double> getRanks() { return nodeComputedStats.entrySet().stream() .collect(Collectors.toMap(Map.Entry::getKey, e -> e.getValue().rank(clientOutgoingConnections.getOrDefault(e.getKey(), 0L)))); } }
@Override public void writeTo(StreamOutput out) throws IOException { out.writeMap(this.clientOutgoingConnections, StreamOutput::writeString, StreamOutput::writeLong); out.writeMap(this.nodeComputedStats, StreamOutput::writeString, (stream, stats) -> stats.writeTo(stream)); }
public double rank(long outstandingRequests) { if (cachedRank == 0) { cachedRank = innerRank(outstandingRequests); } return cachedRank; }
/** * Optionally return a {@code NodeStatistics} for the given nodeid, if * response information exists for the given node. Returns an empty * {@code Optional} if the node was not found. */ public Optional<ComputedNodeStats> getNodeStatistics(final String nodeId) { final int clientNum = nodeIdToStats.size(); return Optional.ofNullable(nodeIdToStats.get(nodeId)).map(ns -> new ComputedNodeStats(clientNum, ns)); }
public Map<String, ComputedNodeStats> getAllNodeStatistics() { final int clientNum = nodeIdToStats.size(); // Transform the mutable object internally used for accounting into the computed version Map<String, ComputedNodeStats> nodeStats = new HashMap<>(nodeIdToStats.size()); nodeIdToStats.forEach((k, v) -> { nodeStats.put(k, new ComputedNodeStats(clientNum, v)); }); return nodeStats; }
public double rank(long outstandingRequests) { if (cachedRank == 0) { cachedRank = innerRank(outstandingRequests); } return cachedRank; }
public Map<String, ComputedNodeStats> getAllNodeStatistics() { final int clientNum = nodeIdToStats.size(); // Transform the mutable object internally used for accounting into the computed version Map<String, ComputedNodeStats> nodeStats = new HashMap<>(nodeIdToStats.size()); nodeIdToStats.forEach((k, v) -> { nodeStats.put(k, new ComputedNodeStats(clientNum, v)); }); return nodeStats; }
private static Map<String, Double> rankNodes(final Map<String, Optional<ResponseCollectorService.ComputedNodeStats>> nodeStats, final Map<String, Long> nodeSearchCounts) { final Map<String, Double> nodeRanks = new HashMap<>(nodeStats.size()); for (Map.Entry<String, Optional<ResponseCollectorService.ComputedNodeStats>> entry : nodeStats.entrySet()) { Optional<ResponseCollectorService.ComputedNodeStats> maybeStats = entry.getValue(); maybeStats.ifPresent(stats -> { final String nodeId = entry.getKey(); nodeRanks.put(nodeId, stats.rank(nodeSearchCounts.getOrDefault(nodeId, 1L))); }); } return nodeRanks; }
private static Map<String, Double> rankNodes(final Map<String, Optional<ResponseCollectorService.ComputedNodeStats>> nodeStats, final Map<String, Long> nodeSearchCounts) { final Map<String, Double> nodeRanks = new HashMap<>(nodeStats.size()); for (Map.Entry<String, Optional<ResponseCollectorService.ComputedNodeStats>> entry : nodeStats.entrySet()) { Optional<ResponseCollectorService.ComputedNodeStats> maybeStats = entry.getValue(); maybeStats.ifPresent(stats -> { final String nodeId = entry.getKey(); nodeRanks.put(nodeId, stats.rank(nodeSearchCounts.getOrDefault(nodeId, 1L))); }); } return nodeRanks; }
@Override public String toString() { StringBuilder sb = new StringBuilder("ComputedNodeStats["); sb.append(nodeId).append("]("); sb.append("nodes: ").append(clientNum); sb.append(", queue: ").append(queueSize); sb.append(", response time: ").append(String.format(Locale.ROOT, "%.1f", responseTime)); sb.append(", service time: ").append(String.format(Locale.ROOT, "%.1f", serviceTime)); sb.append(", rank: ").append(String.format(Locale.ROOT, "%.1f", rank(1))); sb.append(")"); return sb.toString(); } }