1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Speed Of Multi Threaded Non Socket Application

Discussion in 'General Programming Chat' started by ejrussell, Mar 31, 2012.

  1. ejrussell

    ejrussell Regular Member

    Joined:
    May 11, 2010
    Messages:
    207
    Likes Received:
    8
    If I had an application that was a content generator and was generating millions of pages for 1000 websites lets say. If I were to make it multi threaded would it be any faster. The reason Im asking is because an application that connects to the internet with many threads would be faster because many threads are established and then many TCP/IP requests are sent and received. If there was only one thread then there is a wait time for a request to come back. In this time other requests could be sent and/or handled. But in an application that is all local is there any benefit to multi threading.
     
  2. weedsmoker

    weedsmoker Junior Member

    Joined:
    May 2, 2011
    Messages:
    190
    Likes Received:
    79
    Every operation consumes time and you'll spend less time = increase speed of application execution if you perform those operations in parallel and not sequential.
    Sometimes multi threading isn't needed, example: file IO access.
     
  3. ejrussell

    ejrussell Regular Member

    Joined:
    May 11, 2010
    Messages:
    207
    Likes Received:
    8
    Are you positive? Because in this instance the resources like RAM, CPU, Single harddrive are shared and there is a certain overhead of monitoring each thread and having the harddrive needle move from place to place, the pointer in the RAM and CPU also move from place to place. It could easily be slower then faster since with lots of threads there will most likely be more movement not less. Pages of information have to go into memory and out of memory. This is all major overhead and without the saving in extra lag in the TCP/IP connections then it could be slower not faster. That is why Im asking.
     
  4. jazzc

    jazzc Moderator Staff Member Moderator Jr. VIP

    Joined:
    Jan 27, 2009
    Messages:
    2,468
    Likes Received:
    10,143
    1 thread - 1 core
    Many threads - utilizes all the cores

    So, if your app is mostly CPU intensive, multi-threading can benefit you.

    The real answer depends on what 's the bottleneck of your task. Is it CPU, memory, IO? Can the task actually be parallelized efficiently (for example, does not heavily depend on previous results)?

    Other optimizations are also possible. For example, if it 's got a lot of IO but not huge datasets, a ram disk could boost performance. If it has huge datasets and IO, using many nodes would help, etc. So, the answer is problem specific.
     
    • Thanks Thanks x 3
  5. blancog76

    blancog76 Registered Member

    Joined:
    Jun 25, 2011
    Messages:
    74
    Likes Received:
    16
    Occupation:
    Mad Coder
    as jazzc stated, we will need to know more about your architecture to help. it is ridiculous to assume that a web server of any type whether apache, iis, jetty, etc. would be single threaded and it sounds to me as if you are writing a mini-web server as you will be serving 1000 of content consumers. also sounds like you way under appropriated the hardware needs of this
     
  6. weedsmoker

    weedsmoker Junior Member

    Joined:
    May 2, 2011
    Messages:
    190
    Likes Received:
    79
    My example once again: if you want to use threads to store some data to file on HDD, file is locked while one thread accessing it, so you can't properly parallelize the job to get significant performance gain.
    jazzc was clear enough:
    "The real answer depends on what 's the bottleneck of your task. Is it CPU, memory, IO? Can the task actually be parallelized efficiently (for example, does not heavily depend on previous results)?"
     
  7. ejrussell

    ejrussell Regular Member

    Joined:
    May 11, 2010
    Messages:
    207
    Likes Received:
    8

    Cany you please explain what is a huge dataset?
    What is I/O?
    What is a ram disk?

    Thanks
     
  8. jazzc

    jazzc Moderator Staff Member Moderator Jr. VIP

    Joined:
    Jan 27, 2009
    Messages:
    2,468
    Likes Received:
    10,143
    Really big data files your program must process.

    Activity on storage hardware like disks.

    A part of RAM (pc memory) that is configured to imitate as a storage device, like a hard disk. Because RAM is much much faster than a real hard disk, IO activity takes less time.
     
    • Thanks Thanks x 1
  9. timmylang

    timmylang Junior Member

    Joined:
    Mar 3, 2011
    Messages:
    172
    Likes Received:
    49
    Location:
    BotLand
    Can also depend on how many threads, as far as how much benefit you will see..

    I ran a bot to make emails, 25 threads... took 30 minutes...

    same bot, same amount of emails... 100 threads, too 19 minutes...

    faster, but not 4 times faster.. So there can be bottlenecks somewhere
     
  10. ejrussell

    ejrussell Regular Member

    Joined:
    May 11, 2010
    Messages:
    207
    Likes Received:
    8
    yeah, but remember is not a socket application.
     
  11. ejrussell

    ejrussell Regular Member

    Joined:
    May 11, 2010
    Messages:
    207
    Likes Received:
    8
    Also what does using many nodes mean?
     
  12. ejrussell

    ejrussell Regular Member

    Joined:
    May 11, 2010
    Messages:
    207
    Likes Received:
    8
    Also

    Is there any script in php that does not need any special packages installed and does not need shell access.

    Also do most webhosts allow shell access to unpack using a script

    something like

    <?php system('unzip zipFileName.zip'); ?>
     
  13. jazzc

    jazzc Moderator Staff Member Moderator Jr. VIP

    Joined:
    Jan 27, 2009
    Messages:
    2,468
    Likes Received:
    10,143
    In that case, multi-threading is probably not going to help. Is it not possible to store data on temporary files and then combine them in one? Most of the times we need to refactor the execution flow to make the task good for parallelism.
     
    Last edited: Mar 31, 2012
  14. jazzc

    jazzc Moderator Staff Member Moderator Jr. VIP

    Joined:
    Jan 27, 2009
    Messages:
    2,468
    Likes Received:
    10,143
    Computers that are set to do part of the task - for example a database could be split in multiple computers (e.g. MongoDB).
     
    • Thanks Thanks x 1
  15. ejrussell

    ejrussell Regular Member

    Joined:
    May 11, 2010
    Messages:
    207
    Likes Received:
    8
    Oh ok or for example one database on a single core?
     
  16. jazzc

    jazzc Moderator Staff Member Moderator Jr. VIP

    Joined:
    Jan 27, 2009
    Messages:
    2,468
    Likes Received:
    10,143
    • Thanks Thanks x 1
  17. ejrussell

    ejrussell Regular Member

    Joined:
    May 11, 2010
    Messages:
    207
    Likes Received:
    8
    thanks
     
  18. -SICK-

    -SICK- Registered Member

    Joined:
    Jul 17, 2011
    Messages:
    53
    Likes Received:
    22
    For Networking Problems, you won't find another way but Threading.
    When done correctly, it can really do some magic. I can not think about network IO without thinking about threading. The reason for this basically, just like you had mentioned in your first post, are those blocking calls and waits for network codes and responses.
    These calls are not cpu heavy and should be threaded from the very beginning.

    On the other hand, keep in mind that threaded development takes some time and locking can be very difficult to manage. You have to consider the value of the time you spend on working for a threaded network implementation.
    So my advice is to not make a single-threaded application design and start thinking in threads from the very beginning.

    I also have to say that the processor count does not really matter, when it comes to networking. It sure has an impact on how much you can do but you can not rely on the processor count as a performance measurement (for example: 1 thread per core. This would not make any sense in this regard)

    kind regards,
    rapidcc
     
    Last edited: Mar 31, 2012
  19. sockpuppet

    sockpuppet Junior Member

    Joined:
    Nov 7, 2011
    Messages:
    155
    Likes Received:
    145
  20. -SICK-

    -SICK- Registered Member

    Joined:
    Jul 17, 2011
    Messages:
    53
    Likes Received:
    22