Skip to content

Commit

Permalink
Add loadtest page
Browse files Browse the repository at this point in the history
Only allow a user run loadtest once every 24 hours
  • Loading branch information
qcgg committed May 27, 2018
1 parent fde03c2 commit ad146a2
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
21 changes: 13 additions & 8 deletions quarkchain/cluster/master.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ def __init__(self, env, rootState, name="master"):
self.name = name

self.defaultArtificialTxConfig = ArtificialTxConfig(0, 0)
self.artificialTxConfig = self.defaultArtificialTxConfig
self.artificialTxConfig = None # None means no loadtest running
self.synchronizer = Synchronizer()

# branch value -> ShardStats
Expand Down Expand Up @@ -484,7 +484,7 @@ async def __getMinorBlockToMine(self, branch, address):
request = GetNextBlockToMineRequest(
branch=branch,
address=address.addressInBranch(branch),
artificialTxConfig=self.artificialTxConfig,
artificialTxConfig=self.artificialTxConfig if self.artificialTxConfig else self.defaultArtificialTxConfig,
)
slave = self.getSlaveConnection(branch)
_, response, _ = await slave.writeRpcRequest(ClusterOp.GET_NEXT_BLOCK_TO_MINE_REQUEST, request)
Expand Down Expand Up @@ -704,17 +704,19 @@ def destroyPeerClusterConnections(self, clusterPeerId):
cmd=DestroyClusterPeerConnectionCommand(clusterPeerId))

def setArtificialTxConfig(self, numTxPerBlock, xShardTxPercent, seconds):
''' Do NOT revert if seconds <= 0 '''
''' If seconds <= 0 udpate the default config and also cancel ongoing loadtest '''
async def revertLater():
await asyncio.sleep(seconds)
self.artificialTxConfig = self.defaultArtificialTxConfig
self.artificialTxConfig = None

newConfig = ArtificialTxConfig(numTxPerBlock, xShardTxPercent)
if seconds > 0:
asyncio.ensure_future(revertLater())
if not self.artificialTxConfig:
asyncio.ensure_future(revertLater())
self.artificialTxConfig = newConfig
else:
self.defaultArtificialTxConfig = newConfig
self.artificialTxConfig = newConfig
self.artificialTxConfig = None

def updateShardStats(self, shardStats):
self.branchToShardStats[shardStats.branch.value] = shardStats
Expand All @@ -732,16 +734,19 @@ async def getStats(self):
txCount60s = sum([shardStats.txCount60s for shardStats in self.branchToShardStats.values()])
blockCount60s = sum([shardStats.blockCount60s for shardStats in self.branchToShardStats.values()])
pendingTxCount = sum([shardStats.pendingTxCount for shardStats in self.branchToShardStats.values()])
artificialTxConfig = self.artificialTxConfig if self.artificialTxConfig else self.defaultArtificialTxConfig
return {
"shardServerCount": len(self.slavePool),
"shardSize": self.__getShardSize(),
"rootHeight": self.rootState.tip.height,
"rootTimestamp": self.rootState.tip.createTime,
"txCount60s": txCount60s,
"blockCount60s": blockCount60s,
"pendingTxCount": pendingTxCount,
"syncing": self.synchronizer.running,
"numTxPerBlock": self.artificialTxConfig.numTxPerBlock,
"xShardTxPercent": self.artificialTxConfig.xShardTxPercent,
"loadtesting": self.artificialTxConfig is not None,
"numTxPerBlock": artificialTxConfig.numTxPerBlock,
"xShardTxPercent": artificialTxConfig.xShardTxPercent,
"shards": shards,
"cpus": psutil.cpu_percent(percpu=True),
}
Expand Down
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
aiohttp >= 3.1.3
async_armor >= 0.0.2
coincurve >= 7.1.0
devp2p >= 0.9.3
devp2p
Django >= 2.0.0
django-extensions >= 2.0.0
decorator >= 4.2.1
ecdsa >= 0.13
ethereum >= 2.3.0
ethereum
gitpython >=2.1.9
jsonrpcclient >= 2.5.2
jsonrpcserver >= 3.5.4
Expand Down

0 comments on commit ad146a2

Please sign in to comment.