Dynamoose query performance degradation, speed delay

54 views Asked by At

I'm querying DynamoDB using Dynamoose, but even though there are only about 270 entries, the query speed is significantly slow. What could be the factors causing this performance degradation when the query and model schema are as follows? I would like to inquire how to improve the query speed.

const beforeBatchsQuery = new Date();
console.log("query before time", beforeBatchsQuery);

let batchs = await BatchsModel.query("statusValue")
.eq(statusValue)
.using("statusValue-sortKey-index")
.where("sortKey")
.ge(sortKey)
.all()
.exec();

const afterBatchsQuery = new Date();
console.log("query after time", afterBatchsQuery);
const schema = new dynamoose.Schema(
  {
    pk: {
      type: String,
      // validate: (val) => /^batch#/.test(val),
      hashKey: true,
    },
    sk: {
      type: String,
      rangeKey: true,
    },
    afterTuition: {
      type: String,
      required: false,
    },
    applicationProcess: {
      type: Array,
      schema: [
        {
          type: Array,
          schema: [String],
          required: false,
        },
      ],
      required: false,
    },
    applicationProcessText: String,

    batchId: {
      type: String,
      required: false,
    },
    batchName: {
      type: String,
      required: false,
    },
    bootOption: {
      type: String,
      required: false,
    },
    brandName: {
      type: String,
      required: false,
    },
    campId: {
      type: String,
      required: false,
    },
    campUrl: {
      type: String,
      required: false,
    },
    categories: {
      type: Array,
      schema: [String],
      required: false,
    },
    challengeWay: {
      type: String,
      required: false,
    },
    city: {
      type: Array,
      schema: [String],
      required: false,
    },
    classTypeOption: {
      type: Array,
      schema: [String],
      required: false,
    },
    company: {
      type: String,
      required: false,
    },
    companyId: {
      type: String,
      required: false,
    },
    companyIds: {
      type: Array,
      schema: [
        {
          type: Object,
          schema: {
            companyId: String,
            companyRole: String,
            companyName: String,
          },
        },
      ],
    },
    computer: {
      type: String,
      required: false,
    },
    computerOption: {
      type: String,
      required: false,
    },
    costOption: {
      type: String,
      required: false,
    },
    courseValue: {
      type: Number,
      required: false,
    },
    createdAt: {
      type: String,
      required: false,
    },
    createDate: {
      type: String,
      required: false,
    },
    curriculumFile: {
      type: String,
      required: false,
    },

    curriculumUrl: {
      type: String,
      required: false,
    },
    cyclic: {
      type: Boolean,
      required: false,
    },
    dateFixed: {
      type: Object,
      schema: {
        regDate: String,
        regEndDate: String,
        endDate: String,
        startDate: String,
      },
    },
    dateStrings: {
      type: Object,
      schema: {
        regDate: String,
        regEndDate: String,
        endDate: String,
        startDate: String,
      },
    },
    deleted: {
      type: Boolean,
      required: false,
    },
    description: {
      type: [Object, String],
      schema: {
        benefits: {
          type: Array,
          schema: [String],
          required: false,
        },
        targets: {
          type: Array,
          schema: [String],
          required: false,
        },
        goals: {
          type: Array,
          schema: [String],
          required: false,
        },
      },
      schema: String,
      required: false,
    },

    earlyBirdEndDate: {
      type: String,
      required: false,
    },
    endDate: {
      type: String,
      required: false,
    },
    endDateFixed: {
      type: String,
      required: false,
    },
    entryFee: {
      type: [Number, dynamoose.type.NULL],
      required: false,
    },
    etcComputerChecked: {
      type: Boolean,
      required: false,
    },
    etcSubsidyChecked: {
      type: Boolean,
      required: false,
    },
    etcSubsidyText: {
      type: String,
      required: false,
    },
    govtCost: {
      type: Boolean,
      required: false,
    },
    govtCostValue: {
      type: String,
      required: false,
    },
    hasTracks: {
      type: Boolean,
      required: false,
    },
    hrdSeperated: {
      type: Boolean,
      required: false,
    },
    image: {
      type: String,
      required: false,
    },
    jobOpportunityText: String,

    jobSearchingServiceValues: {
      type: Array,
      schema: [Number],
    },
    keywords: {
      type: Array,
      schema: [String],
    },

    nbcardBalance: Boolean,
    nbcardRequired: Boolean,
    offlineRequired: Boolean,
    onoff: {
      type: String,
      required: false,
    },
    openCycle: {
      type: String,
      required: false,
    },

    partTime: Boolean,
    passRequired: Boolean,
    period: Number,
    place: {
      type: String,
      required: false,
    },
    preCourseOption: {
      type: Array,
      schema: [String],
    },
    preferentialTreatment: String,
    preNotice: Boolean,
    preNoticeEndDate: String,
    prepLevel: {
      type: Array,
      schema: [String],
    },
    projectValues: {
      type: Array,
      schema: [Number],
    },
    qualification: String,
    quota: Number,
    recommendedPreKnowledge: String,
    redirectCamp: {
      type: Object,
      schema: {
        batchId: String,
        title: String,
        campId: String,
      },
      required: false,
    },
    regDate: {
      type: String,
      required: false,
    },
    regDateFixed: {
      type: String,
      required: false,
    },
    regEndDate: {
      type: String,
      required: false,
    },
    regEndDateFixed: {
      type: String,
      required: false,
    },
    remark: {
      type: String,
      required: false,
    },
    requiredPreKnowledge: String,
    returnFee: {
      type: [Number, dynamoose.type.NULL],
      required: false,
    },
    reviews: {
      type: [String, dynamoose.type.NULL],
      required: false,
    },
    searchKeywords: {
      type: Object,
      schema: {
        keyword: String,
        dateRestrict: Number,
        includeKeyword: String,
      },
    },    
    sortKey: {
      type: String,
      required: true
    },
    startDate: {
      type: String,
      required: false,
    },
    startDateFixed: {
      type: String,
      required: false,
    },
    statusValue: {
      type: Number,
      required: true,
      index: {
        global: true,
        name: "statusValue-sortKey-index",
        hashKey: "statusValue",
        rangeKey: "sortKey",
        project: true,
        throughput: "ON_DEMAND",
      },
    },
    studyDayOption: Number,
    studyTime: {
      type: Array,
      schema: [
        {
          type: Object,
          schema: {
            startTime: String,
            endTime: String,
          },
        },
      ],
      required: false,
    },
    studyTimeFixed: {
      type: Array,
      schema: [Boolean],
    },
    studyTimePerUnit: {
      type: [String, Number],
      required: false,
    },
    studyTimeUnit: {
      type: String,
      required: false,
    },
    subsidyValues: Array,
    tags: {
      type: Array,
      schema: [String],
      required: false,
    },
    timeSpecified: {
      type: Object,
      schema: {
        regEndDate: Boolean,
        regDate: Boolean,
      },
      required: false,
    },
    timeStrings: {
      type: Object,
      schema: {
        regEndDate: String,
        regDate: String,
      },
      required: false,
    },
    title: {
      type: String,
      required: false,
    },
    tracks: {
      type: Array,
      schema: [
        {
          type: Object,
          schema: {
            category: String,
            keywords: {
              type: Array,
              schema: [String],
              required: false,
            },
            quota: Number,
            tags: {
              type: Array,
              schema: [String],
              required: false,
            },
          },
        },
      ],
      required: false,
    },
    tuition: Number,

    updatedAt: {
      type: String,
      required: false,
    },
  },
  {
    timestamps: false,
    saveUnknown: ["studyTimes.**", "assets.**", "jobOpportunityValues.**", "hrd.**", "earlyBird.**" ],
    indexes: {
      "statusValue-sortKey-index": { 
          type: 'global',
          hashKey: 'statusValue',
          rangeKey: 'sortKey',
          project: true, // 모든 필드 포함 (또는 필요한 필드만 지정)
          // throughput: "ON_DEMAND"
      }
    }
  }
);

const BatchsModel = dynamoose.model("abcd", schema, {
  create: false,
  waitForActive: false
});

module.exports = BatchsModel;

It takes about 8-10 seconds to execute the query. Could you please suggest ways to improve the query speed?

Currently, the query speed is taking about 8-10 seconds, but I would like to see a significant improvement in this speed. Ideally, it would be great if it could be reduced to within 1 second.

0

There are 0 answers