• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Does performance improves with multithreading

 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,
I've a doubt regarding performance improvement in multithreading. Lets assume I have to execute 100 tasks(Each one will take equal time to execute) and there is no database dependence or there is no need to wait for anything, for each of these tasks.

In this case,lets assume I've 10 threads which are executing these 100 tasks.what performance improvement can I get by using multithreading, instead of using single threading and executing my tasks one by one.

Because as far as I know, even in case of multithreading only one thread can execute at a time (My machine has a single processor). so even in multithreading, all threads will follow some kind of time slicing mechanisms. So I feel that the total time to execuete all the 100 tasks by using Single threading or multithreading is the same. Am I correct (or) I didn't understand something about multithreading regarding performance improvement? Please reply.

Thanks in Advance,
VarunJ
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It sounds like there would be no speedup by using multiple threads, and possible a slowdown due to the overhead of context switching. If all the work to be done is just computation (no disk or network I/O), then you're right that there isn't any scope for parallelism.
 
Rancher
Posts: 4803
7
Mac OS X VI Editor Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The work done is the same, single threaded or multi-threaded. Except that multithreaded has some overhead, so it uses a bit more.

If you are CPU bound and on a single CPU, multi-threading will be slower by the overhead.

If you are IO bound in any way, it may be faster to multi-thread. IO can mean anything here, from waiting for a user to click on a form, to reading a disk or talking to a Sql database on another computer.

Today, quad processor chips are common. Multi-threading can give you nearly a 4 to one improvement in execution time (altho 3 to one is more likely)

Soon, Intel will have 8, 16, and 32 processor chips.
 
reply
    Bookmark Topic Watch Topic
  • New Topic