Skip to content

Commit

Permalink
refactor: optimize create job task of control plane (#415)
Browse files Browse the repository at this point in the history
optimized create job task of control plane by changing the DB write task to insert multiple entries in batch, instead of original method of inserting one by one.
changing it to insert multiple entries at once at DB makes the overall create job procedure faster.
in addition, nginx timeout and message size parameters are updated for scalable create job task.
  • Loading branch information
jaemin-shin committed May 17, 2023
1 parent 2a5e4b5 commit e328ebf
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
22 changes: 10 additions & 12 deletions cmd/controller/app/database/mongodb/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ func (db *MongoService) CreateTasks(tasks []objects.Task, dirty bool) error {
// TODO: implement this
}()

var updates []mongo.WriteModel

for _, task := range tasks {
cfgData, err := json.Marshal(&task.JobConfig)
if err != nil {
Expand All @@ -69,19 +71,15 @@ func (db *MongoService) CreateTasks(tasks []objects.Task, dirty bool) error {
}
zap.S().Debugf("taskID %s is assigned compute %s", task.TaskId, task.ComputeId)

after := options.After
upsert := true
opts := options.FindOneAndUpdateOptions{
ReturnDocument: &after,
Upsert: &upsert,
}
updateModel := mongo.NewUpdateOneModel().SetFilter(filter).SetUpdate(update).SetUpsert(true)
updates = append(updates, updateModel)
}

var updatedDoc bson.M
err = db.taskCollection.FindOneAndUpdate(context.TODO(), filter, update, &opts).Decode(&updatedDoc)
if err != nil {
zap.S().Errorf("Failed to insert a task: %v", err)
return err
}
opts := options.BulkWriteOptions{}
_, err := db.taskCollection.BulkWrite(context.TODO(), updates, &opts)
if err != nil {
zap.S().Errorf("Failed to insert tasks: %v", err)
return err
}

success = true
Expand Down
4 changes: 4 additions & 0 deletions fiab/helm-chart/control/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ ingress:
annotations:
nginx.ingress.kubernetes.io/rewrite-target: /
cert-manager.io/cluster-issuer: selfsigned
nginx.ingress.kubernetes.io/proxy-body-size: "512m"
nginx.ingress.kubernetes.io/proxy-connect-timeout: "60000"
nginx.ingress.kubernetes.io/proxy-read-timeout: "60000"
nginx.ingress.kubernetes.io/proxy-send-timeout: "60000"
annotationsGrpc:
nginx.ingress.kubernetes.io/ssl-redirect: "true"
nginx.ingress.kubernetes.io/backend-protocol: "GRPC"
Expand Down

0 comments on commit e328ebf

Please sign in to comment.