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 8428047
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T04:56:48+00:00 2026-06-10T04:56:48+00:00

I have a very long sequence of strings which individually need to be processed

  • 0

I have a very long sequence of strings which individually need to be processed by some processing function and then collected as another sequence object. The problem seems to be ideally suited to a fork/join type attack.

The function is a member of a class that is quite expensive to instantiate. But instantiating and sharing a single class object among the futures seemed to cause problems, so I instantiate 4 times the number of processors available and then split them up among the futures.

// instantiate processing class objects
val processors = 1 to SomeNumber map (x=> new MyProcessor)
val processorstream = Stream.continually(processors).flatten
// the input strings
val input: Seq[String] = some sequence of strings
val splitinput = input.grouped(some large number).toStream
// create futures
val mytask = splitinput.zip(processorstream).collect {
    case (subseq of strings, processor) => future {
        map elements of subsequence of strings with processor}}

Then I collect the output like so

val result = mytask.map(x => x.apply()).reduce(_++_) // or some appropriate concatenation operator

My problem is that this does not give me full cpu utilization even though I have 8 cores. It only utilizes one core.

To investigate, an alternative I tried was

val input: Seq[String] = some sequence of strings
// no stage where I split the input into subsequences
val mytask = input.zip(processorstream).collect {
    case (string, processor) => future {
        process string with processor}}
val result = mytask.map(x => x.apply())

This alternative both worked and didn’t work. It achieved full cpu utilization, but several exceptions were thrown because (a hypothesis) the processor was running through each string too fast and sometimes the same processor object would be applied to different strings simultaneously.

I’m even more sure of my hypothesis that the processors are working too fast because if I provide longer input (say, whole text documents instead of 10 word headlines) I get full cpu utilization without any exceptions thrown.

I’ve also tried experimenting with akka futures and scalaz promises and they all seem to only use one cpu when I split the input sequence into subsequences.

So how do I get full cpu utilization with futures in this instance while using subsequences of strings as input?

  • 1 1 Answer
  • 0 Views
  • 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-06-10T04:56:50+00:00Added an answer on June 10, 2026 at 4:56 am

    Per @om-nom-nom :

    input.par.map { s => task(s) }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a very long text and I need to hide everything except the
Imagine you have a very long sequence. What is the most efficient way of
I have a function which works a very slow for my task (it must
currently I have a very long sequence in a file and I wish to
I have a large data set of nucleotide sequences (long strings simply put) which
I'm using a SlickGrid data table and some of my cells have very long
I'm working on an application that will potentially have very long query strings to
I have very long integer sequences that look like this (arbitrary length!): 0000000001110002220033333 Now
I have a very long javascript (so long that it's too long to escape
We have a very long form that has a number of fields and 2

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.