use of com.srotya.sidewinder.core.rpc.Point in project sidewinder by srotya.
the class HTTPDataPointDecoder method channelRead0.
@Override
protected void channelRead0(ChannelHandlerContext ctx, Object msg) throws Exception {
try {
if (ResourceMonitor.getInstance().isReject()) {
logger.warning("Write rejected, insufficient memory");
if (writeResponse(request, ctx)) {
ctx.writeAndFlush(Unpooled.EMPTY_BUFFER).addListener(ChannelFutureListener.CLOSE);
}
return;
}
if (msg instanceof HttpRequest) {
HttpRequest request = this.request = (HttpRequest) msg;
if (HttpUtil.is100ContinueExpected(request)) {
send100Continue(ctx);
}
QueryStringDecoder queryStringDecoder = new QueryStringDecoder(request.uri());
path = queryStringDecoder.path();
Map<String, List<String>> params = queryStringDecoder.parameters();
if (!params.isEmpty()) {
for (Entry<String, List<String>> p : params.entrySet()) {
String key = p.getKey();
if (key.equalsIgnoreCase("db")) {
dbName = p.getValue().get(0);
}
}
}
if (path != null && path.contains("query")) {
Gson gson = new Gson();
JsonObject obj = new JsonObject();
JsonArray ary = new JsonArray();
ary.add(new JsonObject());
obj.add("results", ary);
responseString.append(gson.toJson(obj));
}
}
if (msg instanceof HttpContent) {
HttpContent httpContent = (HttpContent) msg;
ByteBuf byteBuf = httpContent.content();
if (byteBuf.isReadable()) {
requestBuffer.append(byteBuf.toString(CharsetUtil.UTF_8));
}
if (msg instanceof LastHttpContent) {
if (dbName == null) {
responseString.append("Invalid database null");
logger.severe("Invalid database null");
} else {
String payload = requestBuffer.toString();
logger.fine("Request:" + payload);
List<Point> dps = InfluxDecoder.pointsFromString(dbName, payload);
meter.inc(dps.size());
for (Point dp : dps) {
try {
engine.writeDataPoint(dp);
logger.fine("Accepted:" + dp + "\t" + new Date(dp.getTimestamp()));
} catch (IOException e) {
logger.fine("Dropped:" + dp + "\t" + e.getMessage());
responseString.append("Dropped:" + dp);
}
}
}
if (writeResponse(request, ctx)) {
ctx.writeAndFlush(Unpooled.EMPTY_BUFFER).addListener(ChannelFutureListener.CLOSE);
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
use of com.srotya.sidewinder.core.rpc.Point in project sidewinder by srotya.
the class InfluxApi method insertData.
@POST
@Consumes({ MediaType.TEXT_PLAIN })
public void insertData(@QueryParam("db") String dbName, String payload) {
if (payload == null) {
throw new BadRequestException("Empty request no acceptable");
}
List<Point> dps = InfluxDecoder.pointsFromString(dbName, payload);
if (dps.isEmpty()) {
throw new BadRequestException("Empty request no acceptable");
}
meter.mark(dps.size());
for (Point dp : dps) {
try {
storageEngine.writeDataPoint(dp);
} catch (IOException e) {
throw new BadRequestException(e);
}
}
}
use of com.srotya.sidewinder.core.rpc.Point in project sidewinder by srotya.
the class TestMemStorageEngine method testWritePerformance.
public void testWritePerformance() throws Exception {
final MemStorageEngine engine = new MemStorageEngine();
engine.configure(new HashMap<>(), bgTasks);
long timeMillis = System.currentTimeMillis();
int tcount = 12;
ExecutorService es = Executors.newCachedThreadPool();
int count = 1000000;
final int modulator = 100;
final AtomicInteger rejects = new AtomicInteger(0);
for (int k = 0; k < tcount; k++) {
final int j = k;
es.submit(new Thread() {
@Override
public void run() {
long ts = System.currentTimeMillis();
for (int i = 0; i < count; i++) {
if (isInterrupted()) {
break;
}
try {
Point dp = MiscUtils.buildDataPoint("test" + j, "cpu" + (i % modulator), "value", Arrays.asList("test2"), ts + i, i * 1.1);
engine.writeDataPoint(dp);
} catch (IOException e) {
rejects.incrementAndGet();
}
}
}
});
}
es.shutdown();
es.awaitTermination(120, TimeUnit.SECONDS);
int backOff = 30;
while (!es.isTerminated()) {
backOff = backOff * 2;
Thread.sleep(backOff);
}
System.out.println("Write throughput direct " + tcount + "x" + count + ":" + (System.currentTimeMillis() - timeMillis) + "ms with " + rejects.get() + " rejects using " + tcount + "\nWriting " + tcount + " each with " + (modulator) + " measurements");
assertEquals(tcount, engine.getDatabases().size());
for (int i = 0; i < tcount; i++) {
String dbName = "test" + i;
Set<String> allMeasurementsForDb = engine.getAllMeasurementsForDb(dbName);
assertEquals(modulator, allMeasurementsForDb.size());
for (String measurementName : allMeasurementsForDb) {
List<Series> queryDataPoints = engine.queryDataPoints(dbName, measurementName, "value", timeMillis - (3600_000 * 2000), timeMillis + (3600_000 * 2000), null);
assertEquals(1, queryDataPoints.size());
assertEquals(count / modulator, queryDataPoints.iterator().next().getDataPoints().size());
}
}
}
use of com.srotya.sidewinder.core.rpc.Point in project sidewinder by srotya.
the class TestDiskStorageEngine method testConcurrentOperations.
@Test
public void testConcurrentOperations() throws Exception {
MiscUtils.delete(new File("target/dst-6/data"));
final StorageEngine engine = new DiskStorageEngine();
Map<String, String> conf = new HashMap<>();
conf.put("data.dir", "target/dst-6/data");
conf.put("index.dir", "target/dst-6/index");
engine.configure(conf, bgTasks);
final long ts = System.currentTimeMillis();
ExecutorService es = Executors.newFixedThreadPool(2, new BackgrounThreadFactory("wr1"));
String measurementName = "mmm2";
String valueFieldName = "v1";
String dbName = "db9";
String tag = "h=1";
for (int k = 0; k < 2; k++) {
final int p = k;
es.submit(() -> {
long t = ts + p;
for (int i = 0; i < 100; i++) {
Point dp = MiscUtils.buildDataPoint(dbName, measurementName, valueFieldName, Arrays.asList(tag), t + i * 1000, i);
try {
engine.writeDataPoint(dp);
} catch (Exception e) {
e.printStackTrace();
throw new RuntimeException(e);
}
}
System.err.println("Completed writes:" + 100 + " data points");
});
}
es.shutdown();
es.awaitTermination(100, TimeUnit.SECONDS);
assertEquals(1, engine.getAllMeasurementsForDb(dbName).size());
assertEquals(1, engine.getMeasurementMap().size());
try {
TimeSeries timeSeries = engine.getTimeSeries(dbName, measurementName, valueFieldName, Arrays.asList(tag));
assertNotNull(timeSeries);
} catch (ItemNotFoundException e) {
fail("Time series must exist");
}
List<Series> queryDataPoints = engine.queryDataPoints(dbName, measurementName, valueFieldName, ts, ts + 220 * 1000, null);
assertEquals(1, queryDataPoints.size());
Series next = queryDataPoints.iterator().next();
assertEquals(200, next.getDataPoints().size());
}
use of com.srotya.sidewinder.core.rpc.Point in project sidewinder by srotya.
the class TestInfluxDecoder method testFloatMeasurementValueWithoutTimestamp.
@Test
public void testFloatMeasurementValueWithoutTimestamp() {
String testPoints = "cpu value=1.2";
List<Point> dps = InfluxDecoder.pointsFromString("test", testPoints);
assertEquals(1, dps.size());
Point dp = dps.get(0);
assertEquals("cpu", dp.getMeasurementName());
assertEquals(0, dp.getTagsList().size());
assertEquals(1.2, Double.longBitsToDouble(dp.getValue()), 0.01);
long ts = System.currentTimeMillis();
assertEquals(1, (dp.getTimestamp() / ts), 1);
}
Aggregations