Commit f9257399 authored by jianhua.zhang's avatar jianhua.zhang

tps峰值接口重新调整

parent 01679829
...@@ -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);
} }
......
...@@ -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";
/** /**
* 数据同步阀值 * 数据同步阀值
*/ */
......
...@@ -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();
......
...@@ -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);
} }
...@@ -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);
} }
......
...@@ -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);
} }
...@@ -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);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment