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

Possible to stream chunks of JSON data? #222

Open
timendez opened this issue Nov 5, 2020 · 2 comments
Open

Possible to stream chunks of JSON data? #222

timendez opened this issue Nov 5, 2020 · 2 comments

Comments

@timendez
Copy link

timendez commented Nov 5, 2020

Hi, I was consuming a 25gb JSON file (array of objects) and I was profiling my code to try and improve performance:

let second = false;
oboe(myDataStream)
    .node('!.*', myObject => {
      if (second) {
        console.timeEnd('stream');
        process.exit();
      }
      // business logic in here...
      second = true;
      console.time('stream');
      return oboe.drop;
    })

and it takes about 1ms on average per object, which is the bottleneck of my code.

Is there a way where I can have .node send me a chunk of like 500 objects? Or would that not improve performance anyway since technically oboe has already done a large chunk of IO?

Thanks!

@paulsmithkc
Copy link

paulsmithkc commented Nov 23, 2020

I would be interested in any chunking methods as well.

PS: Although they should be identical "![*]" and "!.*" seem to process nodes at different speeds.

@paulsmithkc
Copy link

Managed to implement chunking, and it did make things much faster.

let chunk = [];
const showChunk = () => {
  for (const item of chunk) {
    // show the item
  }
  chunk = [];
};

oboe('/api/stream')
  .node('![*]', item => {
    if (item) {
      chunk.push(item);
      if (chunk.length >= 1000) {
        showChunk(chunk);
      }
    }
    return oboe.drop;
  })
  .done(_ => {
    // show the last chunk
    showChunk(chunk);
  })
  .fail(res => {
    // show the error
  });

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

2 participants