Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Best ways to handle multithreading

 
prasad yard
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Suppose, I am having a program that takes 1 minute to perform some calculations and having such 1000 transactions to calculate. What are the best ways to get this job done in 20 minutes? Do I have to spin 50 threads? Or are there any better ways?
 
Jim Hoglund
Ranch Hand
Posts: 525
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Be careful with your assumption that mulithreading will make your
operations complete sooner. Its overhead may even slow them down
since the same number of calculations must be done by the same
CPU. Have you exhausted your search for better solution algorithms?

Jim ... ...
 
prasad yard
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Kind of, currently it is handled by multi-process application but facing time limitations as number of transactions are increased.
 
prasad yard
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Any suggestions on this problem.
 
Henry Wong
author
Marshal
Pie
Posts: 21506
84
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

First, you need to apply common sense to the problem. Threads doesn't increase the amount of resources that you have, it just makes it possible to use it. For example, if your computer has four cores, and one thread will use one core at 100 percent, then the theoretical maximum is four times faster. And if one thread is barely using any CPU, you need to look into why -- for example, if it is IO bound on the harddisk, then increasing the number of threads just means more threads waiting for the harddisk.

So... if you want to use many threads, you need to also make sure that you have the resources to support such a program. If you don't have the CPU cycles, or the IO capacity, or the network capacity, etc., adding threads won't do anything -- except add another level of complexity.

Henry
 
Lalit Mehra
Ranch Hand
Posts: 384
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i would say ... you better program some new algo which can do your work faster rather than relying on the THREAD mechanism as sir HENRY said ...

you could kill your program alltogether ... never rely on system resources they can crash anytime ... believe me
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic