Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

poor performance on pipeline with buffers #982

Closed
GGeorgi opened this issue Oct 1, 2019 · 10 comments
Closed

poor performance on pipeline with buffers #982

GGeorgi opened this issue Oct 1, 2019 · 10 comments

Comments

@GGeorgi
Copy link

GGeorgi commented Oct 1, 2019

Hi everyone.
I'm trying to insert into redis about 15k buffers but getting poor performance.
But if I try to insert same amount of data using JSON.stringify it works fast.

const pipe = redis.pipeline();
users.map(user => {
   pipe.set(`{users}:${user.id}`, UserModel.encode(user));
});
pipe.exec();
console.log("done");

on pipe.exec(); code gets freeze about for 10 seconds.

Update:
UserModel is protobuf. But this does not matters: Buffer.from(JSON.stringify(user)) is also same.

@knoxcard
Copy link
Contributor

knoxcard commented Oct 4, 2019

@luin - any thoughts?

@tuananh
Copy link
Contributor

tuananh commented Oct 4, 2019

I traced it down and it has something to do with the recently introduced MixedBuffer class that replace the old flex-buffer it seems.

I tried the version 4.9.1 (prior to removing flex-buffer), the performance is much better.

@GGeorgi @knoxcard can you try 4.9.1 to see if it fixes your problem?

@knoxcard
Copy link
Contributor

knoxcard commented Oct 4, 2019

@GGeorgi - which ioredis version are you on?

Also, are you using Yarn or NPM?

@GGeorgi
Copy link
Author

GGeorgi commented Oct 4, 2019

@knoxcard @tuananh
ioredis: 4.14.1
npm: 6.4.1

@knoxcard
Copy link
Contributor

knoxcard commented Oct 4, 2019

@tuananh - @GGeorgi is using the latest version.

@GGeorgi
Copy link
Author

GGeorgi commented Oct 4, 2019

@tuananh performance seems ok at 4.9.1 version

@luin
Copy link
Collaborator

luin commented Oct 6, 2019

Hi @GGeorgi, Could you provide a reproducible example so I can test on my machine? I used the following code and the performance is good (v4.14.1):

const Redis = require('ioredis')
const faker = require('faker')

const redis = new Redis()

// Create a buffer from an object
function encode(obj) {
  return Buffer.from(JSON.stringify(obj))
}

// Generate some fake users
const users = new Array(150000).fill(0).map(() => (
  {
    id: Math.random() * 100000 | 0,
    name: faker.name.findName(),
    email: faker.internet.email(),
    avatar: faker.internet.avatar(),
    ip: faker.internet.ip(),
    phone: faker.phone.phoneNumber(),
    company: faker.company.companyName(),
    createdAt: faker.date.past()
  }
))

const pipe = redis.pipeline();
users.map(user => {
  pipe.set(`{users}:${user.id}`, encode(user));
});

console.log('Start #exec()')
console.time('exec')
pipe.exec();
console.timeEnd('exec')

Prints:

Start #exec()
exec: 38.897ms

@tuananh
Copy link
Contributor

tuananh commented Oct 7, 2019

@luin because you did not await p.exec() there

in v4.9.1 even if you await p.exec(), it's still a lot faster.

@knoxcard2
Copy link

#991

@stale
Copy link

stale bot commented Nov 22, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed after 7 days if no further activity occurs, but feel free to re-open a closed issue if needed.

@stale stale bot added the wontfix label Nov 22, 2019
@stale stale bot closed this as completed Nov 29, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants