Skip to content

Commit

Permalink
Bounded
Browse files Browse the repository at this point in the history
  • Loading branch information
curtisalexander committed Aug 24, 2022
1 parent ccfd3c9 commit e16f481
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions readstat/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#![allow(non_camel_case_types)]
use clap::{clap_derive::ArgEnum, Parser, Subcommand, ValueHint};
use colored::Colorize;
use crossbeam::channel::unbounded;
use crossbeam::channel::bounded;
use log::debug;
use path_abs::{PathAbs, PathInfo};
use rayon::prelude::*;
Expand Down Expand Up @@ -321,8 +321,10 @@ pub fn run(rs: ReadStatCli) -> Result<(), Box<dyn Error + Send + Sync>> {
// Build up offsets
let offsets = build_offsets(total_rows_to_process, total_rows_to_stream)?;

// Create channels
let (s, r) = unbounded();
// Create channels with a capacity of 10
// Unbounded channels can result in extreme memory usage if files are large and
// the reader significantly outpaces the writer
let (s, r) = bounded(10);

// Process data in batches (i.e. stream chunks of rows)
thread::spawn(move || -> Result<(), Box<dyn Error + Send + Sync>> {
Expand Down

0 comments on commit e16f481

Please sign in to comment.