Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
T
tron-explore
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
张建华@五瓣科技
tron-explore
Commits
f9257399
Commit
f9257399
authored
Dec 16, 2020
by
jianhua.zhang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
tps峰值接口重新调整
parent
01679829
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
75 additions
and
5 deletions
+75
-5
Bootstrapper.java
src/main/java/com/wuban/tron/explore/Bootstrapper.java
+4
-1
Constant.java
src/main/java/com/wuban/tron/explore/constant/Constant.java
+5
-0
TransactionControllerV1.java
...n/tron/explore/controller/v1/TransactionControllerV1.java
+11
-2
TransactionRepository.java
...ava/com/wuban/tron/explore/dao/TransactionRepository.java
+8
-0
Engine.java
src/main/java/com/wuban/tron/explore/fetch/Engine.java
+2
-2
TransactionService.java
...va/com/wuban/tron/explore/service/TransactionService.java
+7
-0
TransactionServiceImpl.java
...ban/tron/explore/service/impl/TransactionServiceImpl.java
+38
-0
No files found.
src/main/java/com/wuban/tron/explore/Bootstrapper.java
View file @
f9257399
...
@@ -75,6 +75,9 @@ public class Bootstrapper {
...
@@ -75,6 +75,9 @@ public class Bootstrapper {
// 抓取最新区块高度
// 抓取最新区块高度
this
.
executorService
.
scheduleWithFixedDelay
(()
->
this
.
lastBlockService
.
refresh
(),
0
,
1
,
TimeUnit
.
SECONDS
);
this
.
executorService
.
scheduleWithFixedDelay
(()
->
this
.
lastBlockService
.
refresh
(),
0
,
1
,
TimeUnit
.
SECONDS
);
// 每秒交易tps峰值统计
//this.executorService.scheduleWithFixedDelay(() -> this.transactionService.transTpsCount(0,0), 5, 1, TimeUnit.SECONDS);
// 统计前一天区块、交易数据
// 统计前一天区块、交易数据
this
.
executorService
.
scheduleWithFixedDelay
(()
->
this
.
transactionService
.
censusBlockByLastDay
(),
getInitialDelay
(),
24
*
60
*
60
,
TimeUnit
.
SECONDS
);
this
.
executorService
.
scheduleWithFixedDelay
(()
->
this
.
transactionService
.
censusBlockByLastDay
(),
getInitialDelay
(),
24
*
60
*
60
,
TimeUnit
.
SECONDS
);
}
}
...
@@ -91,4 +94,4 @@ public class Bootstrapper {
...
@@ -91,4 +94,4 @@ public class Bootstrapper {
engine
.
start
();
engine
.
start
();
}
}
}
}
\ No newline at end of file
src/main/java/com/wuban/tron/explore/constant/Constant.java
View file @
f9257399
...
@@ -52,6 +52,11 @@ public class Constant {
...
@@ -52,6 +52,11 @@ public class Constant {
public
static
final
String
CENSUS_TRANS
=
"census_trans"
;
public
static
final
String
CENSUS_TRANS
=
"census_trans"
;
public
static
final
String
CENSUS_BLOCK_SIZE
=
"census_block_size"
;
public
static
final
String
CENSUS_BLOCK_SIZE
=
"census_block_size"
;
/**
* 交易tps峰值
*/
public
static
final
String
TRANS_TPS_PEAK
=
"trans_tps_peak"
;
/**
/**
* 数据同步阀值
* 数据同步阀值
*/
*/
...
...
src/main/java/com/wuban/tron/explore/controller/v1/TransactionControllerV1.java
View file @
f9257399
...
@@ -17,6 +17,7 @@ import com.wuban.tron.explore.util.ResponseKit;
...
@@ -17,6 +17,7 @@ import com.wuban.tron.explore.util.ResponseKit;
import
lombok.RequiredArgsConstructor
;
import
lombok.RequiredArgsConstructor
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.data.redis.core.StringRedisTemplate
;
import
org.springframework.util.CollectionUtils
;
import
org.springframework.util.CollectionUtils
;
import
org.springframework.util.StringUtils
;
import
org.springframework.util.StringUtils
;
import
org.springframework.web.bind.annotation.PathVariable
;
import
org.springframework.web.bind.annotation.PathVariable
;
...
@@ -53,6 +54,8 @@ public class TransactionControllerV1 {
...
@@ -53,6 +54,8 @@ public class TransactionControllerV1 {
private
final
CensusService
censusService
;
private
final
CensusService
censusService
;
private
final
StringRedisTemplate
stringRedisTemplate
;
/**
/**
* 首页 - 搜索
* 首页 - 搜索
*
*
...
@@ -550,14 +553,20 @@ public class TransactionControllerV1 {
...
@@ -550,14 +553,20 @@ public class TransactionControllerV1 {
/*
/*
计算上一分钟交易tps
计算上一分钟交易tps
*/
*/
TransactionExample
example
=
new
TransactionExample
();
/*
TransactionExample example = new TransactionExample();
example.createCriteria().andTimestampBetween(millis, curMillis);
example.createCriteria().andTimestampBetween(millis, curMillis);
List<Transaction> list = this.transactionService.getByExample(example);
List<Transaction> list = this.transactionService.getByExample(example);
BigDecimal tps = new BigDecimal(0);
BigDecimal tps = new BigDecimal(0);
if (!StringUtils.isEmpty(list)) {
if (!StringUtils.isEmpty(list)) {
tps = BigDecimalUtil.getDevide(1, new BigDecimal(list.size()), new BigDecimal(60));
tps = BigDecimalUtil.getDevide(1, new BigDecimal(list.size()), new BigDecimal(60));
}
}
censusModel
.
setTps
(
tps
.
toPlainString
());
censusModel.setTps(tps.toPlainString());*/
String
tpsPeakStr
=
this
.
stringRedisTemplate
.
opsForValue
().
get
(
Constant
.
TRANS_TPS_PEAK
);
Integer
tpsPeak
=
0
;
if
(
tpsPeakStr
!=
null
)
{
tpsPeak
=
Integer
.
valueOf
(
tpsPeakStr
);
}
censusModel
.
setTps
(
tpsPeak
.
toString
());
// 最新区块高度
// 最新区块高度
LastBlock
lastBlock
=
this
.
lastBlockService
.
getOneByExample
();
LastBlock
lastBlock
=
this
.
lastBlockService
.
getOneByExample
();
...
...
src/main/java/com/wuban/tron/explore/dao/TransactionRepository.java
View file @
f9257399
...
@@ -70,4 +70,12 @@ public interface TransactionRepository {
...
@@ -70,4 +70,12 @@ public interface TransactionRepository {
*/
*/
List
<
Transaction
>
selectPageByAddress
(
@Param
(
"address"
)
String
address
);
List
<
Transaction
>
selectPageByAddress
(
@Param
(
"address"
)
String
address
);
/**
* 根据条件检索数据记录数
*
* @param example
* @return
*/
int
countByExample
(
@Param
(
"example"
)
TransactionExample
example
);
}
}
src/main/java/com/wuban/tron/explore/fetch/Engine.java
View file @
f9257399
...
@@ -127,10 +127,10 @@ public class Engine {
...
@@ -127,10 +127,10 @@ public class Engine {
/*
/*
合约事件数据抓取、处理
合约事件数据抓取、处理
*/
*/
/*
this.contractEventHandler = new ContractEventHandler();
this
.
contractEventHandler
=
new
ContractEventHandler
();
this
.
contractEventFetcher
=
new
ContractEventFetcher
<>(
this
.
contractEventHandler
);
this
.
contractEventFetcher
=
new
ContractEventFetcher
<>(
this
.
contractEventHandler
);
this
.
executor
.
execute
(
this
.
contractEventFetcher
);
this
.
executor
.
execute
(
this
.
contractEventFetcher
);
this.executor.execute(this.contractEventHandler);
*/
this
.
executor
.
execute
(
this
.
contractEventHandler
);
}
}
...
...
src/main/java/com/wuban/tron/explore/service/TransactionService.java
View file @
f9257399
...
@@ -90,5 +90,12 @@ public interface TransactionService {
...
@@ -90,5 +90,12 @@ public interface TransactionService {
*/
*/
PageInfo
<
Transaction
>
selectPageByAddress
(
@Param
(
"address"
)
String
address
,
Integer
startIndex
,
Integer
pageSize
);
PageInfo
<
Transaction
>
selectPageByAddress
(
@Param
(
"address"
)
String
address
,
Integer
startIndex
,
Integer
pageSize
);
/**
* 每秒交易tps峰值统计
*
* @param startTime 开始时间(毫秒)
* @param endTime 结束时间(毫秒)
*/
void
transTpsCount
(
long
startTime
,
long
endTime
);
}
}
src/main/java/com/wuban/tron/explore/service/impl/TransactionServiceImpl.java
View file @
f9257399
...
@@ -456,6 +456,44 @@ public class TransactionServiceImpl implements TransactionService {
...
@@ -456,6 +456,44 @@ public class TransactionServiceImpl implements TransactionService {
return
pageInfo
;
return
pageInfo
;
}
}
/**
* 每秒交易tps峰值统计
*
* @param startTime 开始时间(毫秒)
* @param endTime 结束时间(毫秒)
* @return
*/
@Override
public
void
transTpsCount
(
long
startTime
,
long
endTime
)
{
if
(
startTime
==
0L
)
{
/*String endDate = DateUtil.getFormatDate(new Date(), DateUtil.PATTERN_YMD_HMS);
Long endDateSeconds = DateUtil.getDateFromDateStr(endDate, DateUtil.PATTERN_YMD_HMS);
endTime = endDateSeconds;
startTime = endTime - 1 * 1000;*/
startTime
=
System
.
currentTimeMillis
()
-
20
*
1000
;
endTime
=
startTime
+
1000
;
}
TransactionExample
example
=
new
TransactionExample
();
example
.
createCriteria
().
andTimestampBetween
(
startTime
,
endTime
);
int
count
=
this
.
transactionRepository
.
countByExample
(
example
);
/*
当前count - (redis:trans_tps_peak value) > 0 重新设置此值
*/
if
(
count
!=
0
)
{
String
tpsPeakStr
=
this
.
stringRedisTemplate
.
opsForValue
().
get
(
Constant
.
TRANS_TPS_PEAK
);
int
tpsPeak
=
0
;
if
(
tpsPeakStr
!=
null
)
{
tpsPeak
=
Integer
.
valueOf
(
tpsPeakStr
);
}
if
(
count
-
tpsPeak
>
0
)
{
this
.
stringRedisTemplate
.
opsForValue
().
set
(
Constant
.
TRANS_TPS_PEAK
,
Integer
.
valueOf
(
count
).
toString
());
}
}
}
private
void
census
(
String
date
,
String
startDate
,
String
endDate
)
{
private
void
census
(
String
date
,
String
startDate
,
String
endDate
)
{
Long
startDateSeconds
=
DateUtil
.
getDateFromDateStr
(
startDate
,
DateUtil
.
PATTERN_YMD_HMS
);
Long
startDateSeconds
=
DateUtil
.
getDateFromDateStr
(
startDate
,
DateUtil
.
PATTERN_YMD_HMS
);
Long
endDateSeconds
=
DateUtil
.
getDateFromDateStr
(
endDate
,
DateUtil
.
PATTERN_YMD_HMS
);
Long
endDateSeconds
=
DateUtil
.
getDateFromDateStr
(
endDate
,
DateUtil
.
PATTERN_YMD_HMS
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment