Examples of Measurable


Examples of org.apache.kafka.common.metrics.Measurable

            this.maxRecordSizeSensor = metrics.sensor("record-size-max");
            this.maxRecordSizeSensor.add("record-size-max", "The maximum record size", new Max());
            this.maxRecordSizeSensor.add("record-size-avg", "The average record size", new Avg());

            this.metrics.addMetric("requests-in-flight", "The current number of in-flight requests awaiting a response.", new Measurable() {
                public double measure(MetricConfig config, long now) {
                    return client.inFlightRequestCount();
                }
            });
            metrics.addMetric("metadata-age", "The age in seconds of the current producer metadata being used.", new Measurable() {
                public double measure(MetricConfig config, long now) {
                    return (now - metadata.lastUpdate()) / 1000.0;
                }
            });
        }
View Full Code Here

Examples of org.apache.kafka.common.metrics.Measurable

    }

    private void registerMetrics(Metrics metrics) {
        metrics.addMetric("waiting-threads",
                          "The number of user threads blocked waiting for buffer memory to enqueue their records",
                          new Measurable() {
                              public double measure(MetricConfig config, long now) {
                                  return free.queued();
                              }
                          });
        metrics.addMetric("buffer-total-bytes",
                          "The maximum amount of buffer memory the client can use (whether or not it is currently used).",
                          new Measurable() {
                              public double measure(MetricConfig config, long now) {
                                  return free.totalMemory();
                              }
                          });
        metrics.addMetric("buffer-available-bytes",
                          "The total amount of buffer memory that is not being used (either unallocated or in the free list).",
                          new Measurable() {
                              public double measure(MetricConfig config, long now) {
                                  return free.availableMemory();
                              }
                          });
    }
View Full Code Here

Examples of org.apache.kafka.common.metrics.Measurable

            this.ioTime = this.metrics.sensor("io-time");
            this.ioTime.add("io-time-ns-avg", "The average length of time for I/O per select call in nanoseconds.", new Avg());
            this.ioTime.add("io-ratio", "The fraction of time the I/O thread spent doing I/O", new Rate(TimeUnit.NANOSECONDS));

            this.metrics.addMetric("connection-count", "The current number of active connections.", new Measurable() {
                public double measure(MetricConfig config, long now) {
                    return keys.size();
                }
            });
        }
View Full Code Here

Examples of org.apache.kafka.common.metrics.Measurable

    @Override
    public List<NamedMeasurable> stats() {
        List<NamedMeasurable> ms = new ArrayList<NamedMeasurable>(this.percentiles.length);
        for (Percentile percentile : this.percentiles) {
            final double pct = percentile.percentile();
            ms.add(new NamedMeasurable(percentile.name(), percentile.description(), new Measurable() {
                public double measure(MetricConfig config, long now) {
                    return value(config, now, pct / 100.0);
                }
            }));
        }
View Full Code Here

Examples of org.chaidb.db.helper.cache.measurable.Measurable

        final long sizeToBePlused;
        // check if specified key exists
        final boolean keyExists = map.containsKey(key);

        if (keyExists) {
            Measurable existingValue = (Measurable) map.get(key);
            final long existingValueSize = (existingValue == null) ? 0 : existingValue.getRetainedSize();
            sizeToBePlused = valueSize - existingValueSize;
        } else {
            sizeToBePlused = keySize + valueSize;
        }

        // throw exception if size of key/value pair is even larger than the max capacity
        if (keySize + valueSize > sizeBoundaryInBytes) {
            throw new SizeTooLargeException("required=" + sizeToBePlused + "; max capacity=" + sizeBoundaryInBytes);
        }
        // shortcut for key/value pair whose size equals to the max capacity
        if (keySize + valueSize == sizeBoundaryInBytes) {
            map.clear();
            retainedSizeInBytes = sizeBoundaryInBytes;
            return (Measurable) map.put(key, value);
        }

        if (sizeToBePlused + retainedSizeInBytes <= sizeBoundaryInBytes) {
            retainedSizeInBytes += sizeToBePlused;
            return (Measurable) map.put(key, value);
        } else { // have to kickout some existing key'value pairs
            final long smallestSizeToKickout = sizeToBePlused + retainedSizeInBytes - sizeBoundaryInBytes;
            long kickoutSize = 0;
            while (kickoutSize < smallestSizeToKickout) {
                // Get the eldest key.
                Measurable kickoutKey = getEldestKey();
                // If no more key available, break out.
                if (kickoutKey == NO_KEY) {
                    break;
                }
                // Remove the key/value pair.
                Measurable kickoutValue = (Measurable) map.remove(kickoutKey);
                if ((key == kickoutKey) || (key != null && key.equals(kickoutKey))) {
                    // If existing key is kicked out, don't count their size into kickout size.
                    // Because it will be added back later.
                } else {
                    // Calculate size of key/value pair which has been kicked out
                    final long kickoutKeySize = (kickoutKey == null) ? 0 : kickoutKey.getRetainedSize();
                    final long kickoutValueSize = (kickoutValue == null) ? 0 : kickoutValue.getRetainedSize();
                    kickoutSize += (kickoutKeySize + kickoutValueSize);
                }
            }
            retainedSizeInBytes += (sizeToBePlused - kickoutSize);
            return (Measurable) map.put(key, value);
View Full Code Here

Examples of org.chaidb.db.helper.cache.measurable.Measurable

    public Measurable remove(Measurable key) {
        // check if specified key exists
        final boolean keyExists = map.containsKey(key);
        if (keyExists) {
            Measurable value = (Measurable) map.remove(key);
            final long keySize = (key == null) ? 0 : key.getRetainedSize();
            final long valueSize = (value == null) ? 0 : value.getRetainedSize();
            retainedSizeInBytes -= (keySize + valueSize);
            return value;
        } else {
            return null;
        }
View Full Code Here

Examples of org.chaidb.db.helper.cache.measurable.Measurable

    public long calculateRetainedSize() {
        java.util.HashMap copy = new java.util.HashMap(map);
        Iterator keyIterator = copy.keySet().iterator();
        long retainedSize = 0;
        while (keyIterator.hasNext()) {
            Measurable key = (Measurable) keyIterator.next();
            Measurable value = (Measurable) copy.get(key);
            final long keySize = (key == null) ? 0 : key.getRetainedSize();
            final long valueSize = (value == null) ? 0 : value.getRetainedSize();
            retainedSize += (keySize + valueSize);
        }
        return retainedSize;
    }
View Full Code Here

Examples of org.chaidb.db.helper.cache.measurable.Measurable

        final long sizeToBePlused;
        // check if specified key exists
        final boolean keyExists = map.containsKey(key);

        if (keyExists) {
            Measurable existingValue = (Measurable) map.get(key);
            final long existingValueSize = (existingValue == null) ? 0 : existingValue.getRetainedSize();
            sizeToBePlused = valueSize - existingValueSize;
        } else {
            sizeToBePlused = keySize + valueSize;
        }

        // throw exception if size of key/value pair is even larger than the max capacity
        if (keySize + valueSize > sizeBoundaryInBytes) {
            throw new SizeTooLargeException("required=" + sizeToBePlused + "; max capacity=" + sizeBoundaryInBytes);
        }
        // shortcut for key/value pair whose size equals to the max capacity
        if (keySize + valueSize == sizeBoundaryInBytes) {
            map.clear();
            retainedSizeInBytes = sizeBoundaryInBytes;
            return (Measurable) map.put(key, value);
        }

        if (sizeToBePlused + retainedSizeInBytes <= sizeBoundaryInBytes) {
            retainedSizeInBytes += sizeToBePlused;
            return (Measurable) map.put(key, value);
        } else { // have to kickout some existing key'value pairs
            final long smallestSizeToKickout = sizeToBePlused + retainedSizeInBytes - sizeBoundaryInBytes;
            long kickoutSize = 0;
            while (kickoutSize < smallestSizeToKickout) {
                // Get the eldest key.
                Measurable kickoutKey = getEldestKey();
                // If no more key available, break out.
                if (kickoutKey == NO_KEY) {
                    break;
                }
                // Remove the key/value pair.
                Measurable kickoutValue = (Measurable) map.remove(kickoutKey);
                if ((key == kickoutKey) || (key != null && key.equals(kickoutKey))) {
                    // If existing key is kicked out, don't count their size into kickout size.
                    // Because it will be added back later.
                } else {
                    // Calculate size of key/value pair which has been kicked out
                    final long kickoutKeySize = (kickoutKey == null) ? 0 : kickoutKey.getRetainedSize();
                    final long kickoutValueSize = (kickoutValue == null) ? 0 : kickoutValue.getRetainedSize();
                    kickoutSize += (kickoutKeySize + kickoutValueSize);
                }
            }
            retainedSizeInBytes += (sizeToBePlused - kickoutSize);
            return (Measurable) map.put(key, value);
View Full Code Here

Examples of org.chaidb.db.helper.cache.measurable.Measurable

    public Measurable remove(Measurable key) {
        // check if specified key exists
        final boolean keyExists = map.containsKey(key);
        if (keyExists) {
            Measurable value = (Measurable) map.remove(key);
            final long keySize = (key == null) ? 0 : key.getRetainedSize();
            final long valueSize = (value == null) ? 0 : value.getRetainedSize();
            retainedSizeInBytes -= (keySize + valueSize);
            return value;
        } else {
            return null;
        }
View Full Code Here

Examples of org.chaidb.db.helper.cache.measurable.Measurable

    public long calculateRetainedSize() {
        java.util.HashMap copy = new java.util.HashMap(map);
        Iterator keyIterator = copy.keySet().iterator();
        long retainedSize = 0;
        while (keyIterator.hasNext()) {
            Measurable key = (Measurable) keyIterator.next();
            Measurable value = (Measurable) copy.get(key);
            final long keySize = (key == null) ? 0 : key.getRetainedSize();
            final long valueSize = (value == null) ? 0 : value.getRetainedSize();
            retainedSize += (keySize + valueSize);
        }
        return retainedSize;
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.