Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
kvdb
rocksdb
提交
143ee5a1
R
rocksdb
项目概览
kvdb
/
rocksdb
11 个月 前同步成功
通知
0
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
rocksdb
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
143ee5a1
编写于
6月 22, 2014
作者:
A
Ankit Gupta
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add stats collector
上级
40363684
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
174 addition
and
0 deletion
+174
-0
java/org/rocksdb/StatisticsCollector.java
java/org/rocksdb/StatisticsCollector.java
+86
-0
java/org/rocksdb/StatisticsCollectorCallback.java
java/org/rocksdb/StatisticsCollectorCallback.java
+27
-0
java/org/rocksdb/test/StatisticsCollectorTest.java
java/org/rocksdb/test/StatisticsCollectorTest.java
+39
-0
java/org/rocksdb/test/StatsCallbackMock.java
java/org/rocksdb/test/StatsCallbackMock.java
+22
-0
未找到文件。
java/org/rocksdb/StatisticsCollector.java
0 → 100644
浏览文件 @
143ee5a1
// Copyright (c) 2014, Facebook, Inc. All rights reserved.
// This source code is licensed under the BSD-style license found in the
// LICENSE file in the root directory of this source tree. An additional grant
// of patent rights can be found in the PATENTS file in the same directory.
package
org.rocksdb
;
import
java.util.concurrent.ArrayBlockingQueue
;
import
java.util.concurrent.ThreadPoolExecutor
;
import
java.util.concurrent.TimeUnit
;
import
java.util.concurrent.atomic.AtomicBoolean
;
/**
* Helper class to collect DB statistics periodically at a period specified in
* constructor. Callback function (provided in constructor) is called with
* every statistics collection.
*
* Caller should call start() to start statistics collection. Shutdown() should
* be called to stop stats collection and should be called before statistics (
* provided in constructor) reference has been disposed.
*/
public
class
StatisticsCollector
{
private
final
Statistics
_statistics
;
private
final
ThreadPoolExecutor
_threadPoolExecutor
;
private
final
int
_statsCollectionInterval
;
private
final
StatisticsCollectorCallback
_statsCallback
;
private
volatile
boolean
_isRunning
=
true
;
public
StatisticsCollector
(
Statistics
statistics
,
int
statsCollectionIntervalInMilliSeconds
,
StatisticsCollectorCallback
statsCallback
)
{
_statistics
=
statistics
;
_statsCollectionInterval
=
statsCollectionIntervalInMilliSeconds
;
_statsCallback
=
statsCallback
;
_threadPoolExecutor
=
new
ThreadPoolExecutor
(
1
,
1
,
0
,
TimeUnit
.
SECONDS
,
new
ArrayBlockingQueue
<
Runnable
>(
1
));
}
public
void
start
()
{
_threadPoolExecutor
.
submit
(
collectStatistics
());
}
public
void
shutDown
()
throws
InterruptedException
{
_isRunning
=
false
;
_threadPoolExecutor
.
shutdown
();
// Wait for collectStatistics runnable to finish so that disposal of
// statistics does not cause any exceptions to be thrown.
_threadPoolExecutor
.
awaitTermination
(
Integer
.
MAX_VALUE
,
TimeUnit
.
SECONDS
);
}
private
Runnable
collectStatistics
()
{
return
new
Runnable
()
{
@Override
public
void
run
()
{
while
(
_isRunning
)
{
try
{
// Collect ticker data
for
(
TickerType
ticker
:
TickerType
.
values
())
{
long
tickerValue
=
_statistics
.
getTickerCount
(
ticker
);
_statsCallback
.
tickerCallback
(
ticker
,
tickerValue
);
}
// Collect histogram data
for
(
HistogramType
histogramType
:
HistogramType
.
values
())
{
HistogramData
histogramData
=
_statistics
.
geHistogramData
(
histogramType
);
_statsCallback
.
histogramCallback
(
histogramType
,
histogramData
);
}
Thread
.
sleep
(
_statsCollectionInterval
);
}
catch
(
InterruptedException
e
)
{
Thread
.
currentThread
().
interrupt
();
throw
new
RuntimeException
(
"Thread got interrupted!"
,
e
);
}
catch
(
Exception
e
)
{
throw
new
RuntimeException
(
"Error while calculating statistics"
,
e
);
}
}
}
};
}
}
\ No newline at end of file
java/org/rocksdb/StatisticsCollectorCallback.java
0 → 100644
浏览文件 @
143ee5a1
// Copyright (c) 2014, Facebook, Inc. All rights reserved.
// This source code is licensed under the BSD-style license found in the
// LICENSE file in the root directory of this source tree. An additional grant
// of patent rights can be found in the PATENTS file in the same directory.
package
org.rocksdb
;
/**
* Callback interface provided to StatisticsCollector.
* @param tickerType
* @param tickerCount
*/
public
interface
StatisticsCollectorCallback
{
/**
* Callback function to get ticker values.
* @param tickerType Ticker type.
* @param tickerCount Value of ticker type.
*/
void
tickerCallback
(
TickerType
tickerType
,
long
tickerCount
);
/**
* Callback function to get histogram values.
* @param histType Histogram type.
* @param histData Histogram data.
*/
void
histogramCallback
(
HistogramType
histType
,
HistogramData
histData
);
}
\ No newline at end of file
java/org/rocksdb/test/StatisticsCollectorTest.java
0 → 100644
浏览文件 @
143ee5a1
// Copyright (c) 2014, Facebook, Inc. All rights reserved.
// This source code is licensed under the BSD-style license found in the
// LICENSE file in the root directory of this source tree. An additional grant
// of patent rights can be found in the PATENTS file in the same directory.
package
org.rocksdb.test
;
import
org.rocksdb.*
;
public
class
StatisticsCollectorTest
{
static
final
String
db_path
=
"/tmp/backupablejni_db"
;
static
{
RocksDB
.
loadLibrary
();
}
public
static
void
main
(
String
[]
args
)
throws
InterruptedException
,
RocksDBException
{
Options
opt
=
new
Options
().
createStatistics
().
setCreateIfMissing
(
true
);
Statistics
stats
=
opt
.
statisticsPtr
();
RocksDB
db
=
RocksDB
.
open
(
db_path
);
StatsCallbackMock
callback
=
new
StatsCallbackMock
();
StatisticsCollector
statsCollector
=
new
StatisticsCollector
(
stats
,
100
,
callback
);
statsCollector
.
start
();
Thread
.
sleep
(
1000
);
assert
(
callback
.
tickerCallbackCount
>
0
);
assert
(
callback
.
histCallbackCount
>
0
);
statsCollector
.
shutDown
();
db
.
close
();
opt
.
dispose
();
System
.
out
.
println
(
"Stats collector test passed.!"
);
}
}
\ No newline at end of file
java/org/rocksdb/test/StatsCallbackMock.java
0 → 100644
浏览文件 @
143ee5a1
// Copyright (c) 2014, Facebook, Inc. All rights reserved.
// This source code is licensed under the BSD-style license found in the
// LICENSE file in the root directory of this source tree. An additional grant
// of patent rights can be found in the PATENTS file in the same directory.
package
org.rocksdb.test
;
import
org.rocksdb.*
;
public
class
StatsCallbackMock
implements
StatisticsCollectorCallback
{
public
int
tickerCallbackCount
=
0
;
public
int
histCallbackCount
=
0
;
public
void
tickerCallback
(
TickerType
tickerType
,
long
tickerCount
)
{
tickerCallbackCount
++;
}
public
void
histogramCallback
(
HistogramType
histType
,
HistogramData
histData
)
{
histCallbackCount
++;
}
}
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录