Bird
0
0

You want to speed up a Ruby program that downloads many files. Which concurrency approach is best and why?

hard📝 Application Q15 of 15
Ruby - Concurrent Programming
You want to speed up a Ruby program that downloads many files. Which concurrency approach is best and why?
AUse a single thread to download files one by one to avoid complexity.
BUse threads but add sleep calls to slow down downloads.
CUse multiple processes because Ruby threads cannot run in parallel at all.
DUse threads to download files concurrently because IO waits can run in parallel.
Step-by-Step Solution
Solution:
  1. Step 1: Understand IO-bound tasks and concurrency

    Downloading files is IO-bound and benefits from concurrency because waiting for network is slow.
  2. Step 2: Choose concurrency method in Ruby

    Ruby threads can run IO tasks concurrently, improving speed without extra processes.
  3. Final Answer:

    Use threads to download files concurrently because IO waits can run in parallel. -> Option D
  4. Quick Check:

    Threads speed up IO waits in Ruby [OK]
Quick Trick: Use threads for IO tasks to improve speed [OK]
Common Mistakes:
  • Thinking Ruby threads never run in parallel
  • Ignoring concurrency benefits for IO tasks
  • Adding unnecessary sleep calls

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes