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

Under Pressure #541

Closed
refaelos opened this issue Feb 4, 2015 · 9 comments
Closed

Under Pressure #541

refaelos opened this issue Feb 4, 2015 · 9 comments

Comments

@refaelos
Copy link

refaelos commented Feb 4, 2015

Hey,

I have a question and i'm not sure it's related to winston or to the way node.js works.

Why does this fail?

for (var i=0; i<10000000000; i++) logger.info('some message ' + i);

It starts running fine but after some time it's just stuck.

@indexzero
Copy link
Member

Can you give us more context? e.g.: what transports do you have setup with that logger instance?

@refaelos
Copy link
Author

refaelos commented Feb 5, 2015

Regular file transport.

var logger = new (winston.Logger)({
  transports: [
    new (winston.transports.File)({ filename: filename })
  ]
});

@pose
Copy link
Member

pose commented Feb 5, 2015

@refaelos can you try with the following snippet in order to see if there are any errors during logging?

for (var i=0; i<10000000000; i++) {
  logger.info('some message ' + i, function (err) {
    console.log(err);
  });
}

Thanks in advance,

@refaelos
Copy link
Author

refaelos commented Feb 7, 2015

Stuck ... 😕

@joseph-norman
Copy link

So I saw this issue and I've been messing around with it. Here's what I was trying out:

var winston = require('winston');
var filename = 'test.txt';

var logger = new (winston.Logger) ({
  transports: [
    new (winston.transports.File) ({ filename: filename })
  ]
  });

for (var i = 0; i < 10000000000; i++) {
  console.log('starting log');
  logger.info('some message' + i, function (err) {
    if (err) { console.log(err); }
  });
}

I tried with a few other variants that worked fine, such as changing the value of i to significantly less than the above number. I'm noticing that the log file isn't created until the loop is finished (discovered this from increasing the value of i to one extra zero on the end, starting at 100 onwards, where the time to run the app increased significantly).

So I don't think it's sticking, I think it just doesn't produce the file as you'd expect it to (i.e. create it first, then add to it on each iteration).

@indexzero
Copy link
Member

@joseph-norman could you try writing a single line, then when that is done, writing 10000000000 lines? I think this may have to do with our initial buffering before flushing to the file upon create.

@joseph-norman
Copy link

@indexzero I'll give this a go now

@joseph-norman
Copy link

So I added the following to what I had before:

logger.info("one liner", function (err) {
  if (err) {
    console.log(err);
  }
});

There's no file being created in this instance either - the loop is ran immediately afterwards. Obviously this kind of loop is going to be CPU intensive (checking top and I'm seeing an almost constant 100% core usage). I imagine that eventually a file will be created when the buffer is flushed; after this loop is finished.

edit: changed the loop increment count value to 100, and can see both log entries - just for consistency.

@indexzero
Copy link
Member

Duplicate of #288, which is now fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants