noppoMan / npdynamodb

A Node.js Simple Query Builder and ORM for AWS DynamoDB
112 stars 18 forks source link

Timeout locking query #51

Closed davidroman0O closed 7 years ago

davidroman0O commented 7 years ago

Hi!

I'm experimenting on this ORM and i got only one serious issue! Every time, i try the save something (for testing the ORM) it's very slow AND it depend on the timeout parameter when we create the client.

var npd = npdynamodb.createClient(dynamodb, {
    timeout: 2000,   // <-- if we set 5000, our query will make 5s to resolve, and 2s for 2000...
    initialize: () => {
        console.log('ORM OK');
    }
});

It is normal? Normally, the callback who resolve the save function should be handle directly right after the end of the execution, right?

I hope it's just a bug or a misunderstanding! :)

noppoMan commented 7 years ago

Hi David.

Thanks for your reviewing. hmm, I've never seen such a serious problem. I tried to set timeout as 10000 and tested with the following code on my Mac... but the callback who resolve the save function is called immediately. (I used official dynamodb-local instead of actual dynamodb. And Node.js version is v7.0.0)

const npdynamodb = require('npdynamodb');
const AWS = require('aws-sdk');

const dynamodb = new AWS.DynamoDB({
  apiVersion: '2012-08-10',
  accessKeyId: "AWS_KEY",
  secretAccessKey: "AWS_SECRET",
  region: "ap-northeast-1",
  sslEnabled: false,
  endpoint: "localhost:8000"
});

console.time('initializer');
console.time('afterSave');

const npd = npdynamodb.createClient(dynamodb, {
  timeout: 10000,
  initialize: () => {
    console.timeEnd('initializer');
  }
});

const Model = npdynamodb.define("test", {

  npdynamodb: npd,

  hashKey: 'hk',
});

Model.save({
  hk: 1
  message: 'Hi dude!',
})
.then(function(){
  console.timeEnd('afterSave');
});

stdout

initializer: 57.295ms
initializer: 103.823ms
afterSave: 104.064ms

Normally, the callback who resolve the save function should be handle directly right after the end of the execution, right?

Definitely yes.

What Environment did you work with?

Yuki