Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 917171
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T18:10:06+00:00 2026-05-15T18:10:06+00:00

I have a program in which each thread reads in files many lines at

  • 0

I have a program in which each thread reads in files many lines at a time from a file, processes the lines, and writes the lines out to a different file. Four threads split the list of files to process among them. I’m having strange performance issues across two cases:

  • Four files with 50,000 lines each
    • Throughput starts at 700 lines/sec processed, declines to ~100 lines/sec
  • 30,000 files with 12 lines each
    • Throughput starts around 800 lines/sec and remains steady

This is internal software I’m working on so unfortunately I can’t share any source code, but the main steps of the program are:

  1. Split list of files among four worker threads
  2. Start all threads.
  3. Thread reads up to 100 lines at once and stores in String[] array.
  4. Thread applies transformation to all lines in array.
  5. Thread writes lines to a file (not same as input file).
  6. 3-5 repeats for each thread until all files completely processed.

What I don’t understand is why 30k files with 12 lines each gives me greater performance than a few files with many lines each. I would have expected that the overhead of opening and closing the files to be greater than that of reading a single file. In addition, the decline in performance of the former case is exponential in nature.

I’ve set the maximum heap size to 1024 MB and it appears to use 100 MB at most, so an overtaxed GC isn’t the problem. Do you have any other ideas?

  • 1 1 Answer
  • 1 View
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T18:10:07+00:00Added an answer on May 15, 2026 at 6:10 pm

    From your numbers, I guess that GC is probably not the issue. I suspect that this is a normal behavior of a disk, being operated on by many concurrent threads. When the files are big, the disk has to switch context between the threads many times (producing significant disk seek time), and the overhead is apparent. With small files, maybe they are read as a single chunk with no extra seek time, so threads do not interfere with each other too much.

    When working with a single, standard disk, serial IO is usually better that parallel IO.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a program which reads data from 2 text files and then save
I have implemented a multi-threaded program which involves spawning a thread for each user,and
Ok, so I have this program with many (~300) threads, each of which communicates
The program I made throws off threads which start executables through processes. Each thread
I have a multithreaded which does data entry, at a given time each thread
I have a program which dynamically generates a GUI. I don't know how many
I have a program which runs an external, command line utility and reads the
I have a program which takes a long time to complete. I would like
Working in Linux and using C++. I have a program which initiates a thread.
I have written a multithreaded program which does some thinking and prints out some

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.