THIS IS A TEST INSTANCE. ALL YOUR CHANGES WILL BE LOST!!!!
...
单线程写入,同时有 n 个线程查询,测试在有查询的负载下,写入线程最终完成写入的总时间
查询线程是一个无限循环,每次随机选择一个时间序列查询全部数据
写入吞吐
负载 / 查询线程数 | n = 1 (points / ms) | n = 3 (points / ms) | n = 5 (points / ms) | |||
---|---|---|---|---|---|---|
数据结构 | Array | SkipList | Array | SkipList | Array | SkipList |
单序列一千万个点 | 18.93 K | 0.81 K | 14.25 K | 0.70 K | 8.84 K | 0.61 K |
一千序列每序列一万个点 | 16.58 K | 0.36 K | 9.91 K | 0.25 K | 8.19 K | 0.19 K |
十万序列每序列一百个点 | 9.47 K | 0.97 K | 6.50 K | 0.86 K | 4.85 K | 0.72 K |
...
Array/Skiplist查询延迟比随序列中的点数变化趋势
Array/Skiplist查询吞吐比随序列中的点数变化趋势
结论
(1)内存占用:skiplist 的内存占用为 array 的10倍左右
...
(4)读写混合负载查询吞吐:skiplist的随着每序列的点数减少,skiplist的查询性能越来越低,最终会低于Array的查询性能
关键实验代码
单线程:
Code Block |
---|
package data_structure;
import java.util.Random;
public class Main {
private static int timeseriesNum = 1;
private static int size = 10000000;
static Random random = new Random();
public static void main(String[] args) throws InterruptedException {
multiWriteAndRead();
// for memory calculate
Thread.sleep(100000000);
}
private static void multiWriteAndRead() throws InterruptedException {
MemTable[] arrayTable = new MemTable[timeseriesNum];
MemTable[] skipListTable = new MemTable[timeseriesNum];
// skip list
long curTime = System.nanoTime();
for (int i = 0; i < timeseriesNum; i++) {
skipListTable[i] = new SkipListTable(size);
write(skipListTable[i]);
}
long finishTime = System.nanoTime();
System.out.println("SkipList write time: " + (finishTime - curTime) / 1_000_000 + " ms.");
curTime = System.nanoTime();
for (int i = 0; i < timeseriesNum; i++) {
query(skipListTable[i]);
}
finishTime = System.nanoTime();
System.out.println("SkipList query time: " + (finishTime - curTime) / 1_000_000 + " ms.");
// array
curTime = System.nanoTime();
for (int i = 0; i < timeseriesNum; i++) {
arrayTable[i] = new ArrayTable(size);
write(arrayTable[i]);
}
finishTime = System.nanoTime();
System.out.println("Array write time: " + (finishTime - curTime) / 1_000_000 + " ms.");
curTime = System.nanoTime();
for (int i = 0; i < timeseriesNum; i++) {
query(arrayTable[i]);
}
finishTime = System.nanoTime();
System.out.println("Array query time: " + (finishTime - curTime) / 1_000_000 + " ms.");
System.out.println("finished");
}
private static int query(MemTable table){
return table.query();
}
public static void write(MemTable table){
for (int i = 0; i < size; i++) {
if(random.nextDouble() < 0.2){
table.add(random.nextInt(100000) - 50000);
}
else{
table.add(i);
}
}
}
}
|
多线程:
Code Block | ||||
---|---|---|---|---|
| ||||
package data_structure;
import java.util.Random;
import java.util.concurrent.atomic.AtomicLong;
public class MultiMain {
private static int timeseriesNum = 1000_00;
private static int size = 100;
static Random random = new Random();
static MemTable[] memtable = new MemTable[timeseriesNum];
private static int queryThreadNum = 1;
static AtomicLong count = new AtomicLong();
public static void main(String[] args) {
for (int i = 0; i < timeseriesNum; i++) {
memtable[i] = new SkipListTable(size);
}
Thread[] queryThread = new Thread[queryThreadNum];
for (int i = 0; i < queryThreadNum; i++) {
queryThread[i] = new Thread(MultiMain::queryThread);
queryThread[i].start();
}
writeThread();
}
public static void writeThread(){
long curTime = System.nanoTime();
for (int i = 0; i < size; i++) {
for (int j = 0; j < timeseriesNum; j++) {
int cur = random.nextDouble() < 0.05 ? random.nextInt(100000) - 50000 : i;
memtable[j].add(cur);
}
}
long finishTime = System.nanoTime();
long cur = count.get();
System.out.println("Finish time: " + (finishTime - curTime) / 1_000_000 + " ms.");
System.out.println("Read points: " + cur / 1000 / 1000);
}
private static void queryThread(){
while(true){
int loc = random.nextInt(timeseriesNum);
count.addAndGet(memtable[loc].query());
}
}
}
|
Code Block |
---|