From 59a2f1e998d1d5d9a997d0415ecde7942846963c Mon Sep 17 00:00:00 2001 From: georgehao Date: Thu, 21 Sep 2023 22:44:06 +0800 Subject: [PATCH] perf(coordinator): optimize get task's optimistic lock (#960) Co-authored-by: georgehao Co-authored-by: colinlyguo --- common/version/version.go | 2 +- coordinator/internal/logic/provertask/batch_prover_task.go | 2 ++ coordinator/internal/logic/provertask/chunk_prover_task.go | 2 ++ coordinator/internal/orm/batch.go | 1 - coordinator/internal/orm/chunk.go | 1 - 5 files changed, 5 insertions(+), 3 deletions(-) diff --git a/common/version/version.go b/common/version/version.go index fc53e48352..6e42162886 100644 --- a/common/version/version.go +++ b/common/version/version.go @@ -5,7 +5,7 @@ import ( "runtime/debug" ) -var tag = "v4.3.13" +var tag = "v4.3.14" var commit = func() string { if info, ok := debug.ReadBuildInfo(); ok { diff --git a/coordinator/internal/logic/provertask/batch_prover_task.go b/coordinator/internal/logic/provertask/batch_prover_task.go index 335d33c75c..69ebf7a4ea 100644 --- a/coordinator/internal/logic/provertask/batch_prover_task.go +++ b/coordinator/internal/logic/provertask/batch_prover_task.go @@ -4,6 +4,7 @@ import ( "context" "encoding/json" "fmt" + "time" "github.com/gin-gonic/gin" "github.com/prometheus/client_golang/prometheus" @@ -80,6 +81,7 @@ func (bp *BatchProverTask) Assign(ctx *gin.Context, getTaskParameter *coordinato } if rowsAffected == 0 { + time.Sleep(100 * time.Millisecond) continue } diff --git a/coordinator/internal/logic/provertask/chunk_prover_task.go b/coordinator/internal/logic/provertask/chunk_prover_task.go index fba5dbc9bb..648de0e4c4 100644 --- a/coordinator/internal/logic/provertask/chunk_prover_task.go +++ b/coordinator/internal/logic/provertask/chunk_prover_task.go @@ -4,6 +4,7 @@ import ( "context" "encoding/json" "fmt" + "time" "github.com/gin-gonic/gin" "github.com/prometheus/client_golang/prometheus" @@ -84,6 +85,7 @@ func (cp *ChunkProverTask) Assign(ctx *gin.Context, getTaskParameter *coordinato } if rowsAffected == 0 { + time.Sleep(100 * time.Millisecond) continue } diff --git a/coordinator/internal/orm/batch.go b/coordinator/internal/orm/batch.go index de71cb853a..896ece63cd 100644 --- a/coordinator/internal/orm/batch.go +++ b/coordinator/internal/orm/batch.go @@ -79,7 +79,6 @@ func (o *Batch) GetUnassignedBatch(ctx context.Context, maxActiveAttempts, maxTo db = db.Where("total_attempts < ?", maxTotalAttempts) db = db.Where("active_attempts < ?", maxActiveAttempts) db = db.Where("chunk_proofs_status = ?", int(types.ChunkProofsStatusReady)) - db = db.Order("index ASC") var batch Batch err := db.First(&batch).Error diff --git a/coordinator/internal/orm/chunk.go b/coordinator/internal/orm/chunk.go index 2fe914babd..c80dc15cb9 100644 --- a/coordinator/internal/orm/chunk.go +++ b/coordinator/internal/orm/chunk.go @@ -75,7 +75,6 @@ func (o *Chunk) GetUnassignedChunk(ctx context.Context, height int, maxActiveAtt db = db.Where("total_attempts < ?", maxTotalAttempts) db = db.Where("active_attempts < ?", maxActiveAttempts) db = db.Where("end_block_number <= ?", height) - db = db.Order("index ASC") var chunk Chunk err := db.First(&chunk).Error