@@ -69,7 +69,13 @@ public class SyncService {
6969
7070 private final long syncFetchBatchNum = Args .getInstance ().getSyncFetchBatchNum ();
7171
72- private long startSyncNum = 10_000_000 ;
72+ private long startSyncNum = 1 ;
73+ private long requestedCount = 0 ;
74+ private long startRequestTime = 0 ;
75+ private long lastRequestTime = System .currentTimeMillis ();
76+ private long lastReportTime = System .currentTimeMillis ();
77+ private long receiveBlockCount = 0 ;
78+
7379
7480 public void init () {
7581 ExecutorServiceManager .scheduleWithFixedDelay (fetchExecutor , () -> {
@@ -137,16 +143,17 @@ public void processBlock(PeerConnection peer, BlockMessage blockMessage) {
137143// synchronized (blockJustReceived) {
138144// blockJustReceived.put(blockMessage, peer);
139145// }
146+ receiveBlockCount += 1 ;
140147 peer .getSyncBlockToFetch ().remove (blockMessage .getBlockId ());
141148 handleFlag = true ;
142- if (peer .isSyncIdle ()) {
149+ // if (peer.isSyncIdle()) {
143150 if (peer .getRemainNum () > 0
144151 && peer .getSyncBlockToFetch ().size () <= syncFetchBatchNum ) {
145152 syncNext (peer );
146153 } else {
147154 fetchFlag = true ;
148155 }
149- }
156+ // }
150157 }
151158
152159 public void onDisconnect (PeerConnection peer ) {
@@ -249,7 +256,7 @@ private void startFetchSyncBlock() {
249256 requestBlockIds .put (blockId , peer );
250257 peer .getSyncBlockRequested ().put (blockId , System .currentTimeMillis ());
251258 send .get (peer ).add (blockId );
252- if (send .get (peer ).size () >= 1999 ) {
259+ if (send .get (peer ).size () >= 2000 ) {
253260 break ;
254261 }
255262 }
@@ -259,6 +266,24 @@ private void startFetchSyncBlock() {
259266 send .forEach ((peer , blockIds ) -> {
260267 if (!blockIds .isEmpty ()) {
261268 peer .sendMessage (new FetchInvDataMessage (new LinkedList <>(blockIds ), InventoryType .BLOCK ));
269+ requestedCount += blockIds .size ();
270+ long currentTime = System .currentTimeMillis ();
271+ if (startRequestTime > 0 ) {
272+ if (currentTime - lastReportTime > 10 * 1000 ) {
273+ long allQps = StrictMath .floorDiv (requestedCount * 1000 ,
274+ currentTime - startRequestTime );
275+ long currentQps = StrictMath .floorDiv (blockIds .size () * 1000 ,
276+ currentTime - lastRequestTime );
277+ long receiveQps = StrictMath .floorDiv (receiveBlockCount * 1000 ,
278+ currentTime - startRequestTime );
279+ logger .info ("fast request block, allQps: {}, currentQps: {}, receiveQps: {}" ,
280+ allQps , currentQps , receiveQps );
281+ lastReportTime = currentTime ;
282+ }
283+ } else {
284+ startRequestTime = currentTime ;
285+ }
286+ lastRequestTime = currentTime ;
262287 }
263288 });
264289 }
0 commit comments