-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added monitoring sources and channels
- Loading branch information
Showing
15 changed files
with
2,366 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
125 changes: 125 additions & 0 deletions
125
...rent/aksw-commons-io-buffers/src/main/java/org/aksw/commons/io/input/ChannelMonitor2.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
package org.aksw.commons.io.input; | ||
|
||
import java.io.IOException; | ||
import java.io.OutputStream; | ||
import java.io.OutputStreamWriter; | ||
import java.util.Map.Entry; | ||
import java.util.NavigableMap; | ||
import java.util.TreeMap; | ||
import java.util.concurrent.atomic.AtomicLong; | ||
|
||
import com.google.gson.Gson; | ||
import com.google.gson.GsonBuilder; | ||
import com.google.gson.stream.JsonWriter; | ||
|
||
public class ChannelMonitor2 { | ||
public class RangeTracker { | ||
protected long totalDurationNanos; | ||
// protected Set<Integer> readLengths; | ||
protected int minReadLength; | ||
protected int maxReadLength; | ||
protected long totalReadLength; | ||
protected long readCount; | ||
|
||
public RangeTracker() { | ||
this(Integer.MAX_VALUE, 0, 0, 0, 0); | ||
} | ||
|
||
public RangeTracker(int readLength, long totalDurationNanos) { | ||
this(readLength, readLength, readLength, totalDurationNanos, 1); | ||
} | ||
|
||
public RangeTracker(int minReadLength, int maxReadLength, long totalReadLength, long totalDurationNanos, long readCount) { | ||
super(); | ||
this.totalDurationNanos = totalDurationNanos; | ||
this.minReadLength = minReadLength; | ||
this.maxReadLength = maxReadLength; | ||
this.totalReadLength = totalReadLength; | ||
this.readCount = readCount; | ||
} | ||
|
||
public long getTotalDurationNanos() { | ||
return totalDurationNanos; | ||
} | ||
|
||
public int getMinReadLength() { | ||
return minReadLength; | ||
} | ||
|
||
public long getTotalReadLength() { | ||
return totalReadLength; | ||
} | ||
|
||
public int getMaxReadLength() { | ||
return maxReadLength; | ||
} | ||
|
||
public long getReadCount() { | ||
return readCount; | ||
} | ||
|
||
public void add(RangeTracker contrib) { | ||
this.totalDurationNanos += contrib.totalDurationNanos; | ||
this.maxReadLength = Math.max(this.maxReadLength, contrib.maxReadLength); | ||
this.minReadLength = this.minReadLength == -1 | ||
? contrib.minReadLength | ||
: Math.min(this.minReadLength, contrib.minReadLength); | ||
this.totalReadLength += contrib.totalReadLength; | ||
++this.readCount; | ||
} | ||
|
||
@Override | ||
protected RangeTracker clone() { | ||
return new RangeTracker(minReadLength, maxReadLength, totalReadLength, totalDurationNanos, readCount); | ||
} | ||
} | ||
|
||
protected volatile NavigableMap<Long, RangeTracker> trackedReads = new TreeMap<>(); | ||
protected AtomicLong readCounter = new AtomicLong(); | ||
protected AtomicLong readAmount = new AtomicLong(); | ||
|
||
public void addReadAmount(long readAmount) { | ||
this.readAmount.addAndGet(readAmount); | ||
} | ||
|
||
public void incReadCounter() { | ||
this.readCounter.addAndGet(1); | ||
} | ||
|
||
public long getReadCounter() { | ||
return readCounter.get(); | ||
} | ||
|
||
public long getReadAmount() { | ||
return readAmount.get(); | ||
} | ||
|
||
public NavigableMap<Long, RangeTracker> getTrackedReads() { | ||
return trackedReads; | ||
} | ||
|
||
public synchronized void submitReadStats(long offset, long readStartPos, long readEndPos, int readLength, long durationNanos) { | ||
if (readLength > 0) { // Skip lengths that are <= 0 | ||
RangeTracker tracker = trackedReads.computeIfAbsent(offset, o -> new RangeTracker()); | ||
RangeTracker contrib = new RangeTracker(readLength, durationNanos); | ||
tracker.add(contrib); | ||
} | ||
} | ||
|
||
public void dumpJson(OutputStream out) throws IOException { | ||
Gson gson = new GsonBuilder().setPrettyPrinting().create(); | ||
try (JsonWriter w = gson.newJsonWriter(new OutputStreamWriter(out))) { | ||
w.beginArray(); | ||
for (Entry<Long, RangeTracker> e : getTrackedReads().entrySet()) { | ||
w.beginObject(); | ||
w.name("offset"); | ||
w.value(e.getKey()); | ||
w.name("length"); | ||
w.value(e.getValue().getTotalReadLength()); | ||
w.endObject(); | ||
} | ||
w.endArray(); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
...io-buffers/src/main/java/org/aksw/commons/io/input/SeekableReadableSourceWithMonitor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package org.aksw.commons.io.input; | ||
|
||
import java.util.Objects; | ||
|
||
public class SeekableReadableSourceWithMonitor<A, X extends SeekableReadableChannelSource<A>> | ||
extends SeekableReadableSourceWrapperBase<A, X> | ||
{ | ||
protected ChannelMonitor2 channelMonitor; | ||
|
||
public SeekableReadableSourceWithMonitor(X delegate) { | ||
this(delegate, new ChannelMonitor2()); | ||
} | ||
|
||
public ChannelMonitor2 getChannelMonitor() { | ||
return channelMonitor; | ||
} | ||
|
||
public SeekableReadableSourceWithMonitor(X delegate, | ||
ChannelMonitor2 channelMonitor) { | ||
super(Objects.requireNonNull(delegate)); | ||
this.channelMonitor = Objects.requireNonNull(channelMonitor); | ||
} | ||
|
||
@Override | ||
protected SeekableReadableChannel<A> wrap(SeekableReadableChannel<A> delegate) { | ||
return new SeekableReadableChannelWithMonitor<>(delegate, channelMonitor); | ||
} | ||
} |
64 changes: 64 additions & 0 deletions
64
...io-buffers/src/main/java/org/aksw/commons/io/input/SeekableReadableSourceWrapperBase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package org.aksw.commons.io.input; | ||
|
||
import java.io.IOException; | ||
|
||
import org.aksw.commons.io.buffer.array.ArrayOps; | ||
|
||
import com.google.common.collect.Range; | ||
|
||
public abstract class SeekableReadableSourceWrapperBase<A, X extends SeekableReadableChannelSource<A>> | ||
implements SeekableReadableChannelSource<A> | ||
{ | ||
protected X delegate; | ||
|
||
public SeekableReadableSourceWrapperBase(X delegate) { | ||
super(); | ||
this.delegate = delegate; | ||
} | ||
|
||
public X getDelegate() { | ||
return delegate; | ||
} | ||
|
||
@Override | ||
public long size() throws IOException { | ||
return getDelegate().size(); | ||
} | ||
|
||
@Override | ||
public ArrayOps<A> getArrayOps() { | ||
return getDelegate().getArrayOps(); | ||
} | ||
|
||
@Override | ||
public SeekableReadableChannel<A> newReadableChannel() throws IOException { | ||
return wrap(getDelegate().newReadableChannel()); | ||
} | ||
|
||
@Override | ||
public SeekableReadableChannel<A> newReadableChannel(long start) throws IOException { | ||
SeekableReadableChannel<A> result = newReadableChannel(); | ||
result.position(start); | ||
return result; | ||
// return wrap(getDelegate().newReadableChannel(start)); | ||
} | ||
|
||
@Override | ||
public SeekableReadableChannel<A> newReadableChannel(long start, long end) throws IOException { | ||
SeekableReadableChannel<A> result = newReadableChannel(); | ||
result.position(start); | ||
return result; | ||
// return wrap(getDelegate().newReadableChannel(start, end)); | ||
} | ||
|
||
@Override | ||
public SeekableReadableChannel<A> newReadableChannel(Range<Long> range) throws IOException { | ||
throw new UnsupportedOperationException(); | ||
// SeekableReadableChannel<A> result = newReadableChannel(); | ||
// result.position(range.low); | ||
// return result; | ||
// return wrap(getDelegate().newReadableChannel(range)); | ||
} | ||
|
||
protected abstract SeekableReadableChannel<A> wrap(SeekableReadableChannel<A> delegate); | ||
} |
57 changes: 0 additions & 57 deletions
57
...ers/src/main/java/org/aksw/commons/io/input/SeekableReadableSourceWrapperWithMonitor.java
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.