Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how can programmers ensure appropriate usage of multiple processors while writing multi threaded cod

 
aryan Sharma
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
someone asked me if there's anything particular a java programmer should keep in mind while writing concurrent softwares those are deployed on machines with multiple cores , to ensure ideal usage of those multi-processors... my own sense is there's nothing special to be kept in mind by the programmer as the proper usage of the these multiple cores would be taken care by the JVM and deployment time JVM params...

guys let me know your thoughts....
 
Nitesh Kant
Bartender
Posts: 1638
IntelliJ IDE Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Although this is a very vague question, there are a few things that one should actually take care.

1) Any OS or threading library can not speed up a poorly written code. eg: if you have a piece of code that is invoked by every request in a web application and you take a class level lock before executing that code. Your application can never really have a great throughput. This will not make much of a difference on a single processor box but your scalability will be close to zero by adding more processors.

2) Since multiple core (or hyper-threaded) boxes are capable of running multiple threads in parallel so an application should be aware of that when choosing the number of threads that run for that application. One can divide the code in such a way that CPU bound tasks are in a different pool than the IO bound tasks so that they can be scaled/configured differently. Of course, there is a penalty of context switches but one needs to be aware of such things before making an architectural decision.

There are a lot of things that goes into scalability with additional processing power which a programmer should be aware of. Its not really as simple as it sounds.
 
Ulf Dittmer
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Of course, the JVM can only schedule threads to run on multiple cores in parallel if there *are* multiple threads. For a web app, this happens automatically through request-level parallelism (each of which has their own thread), but for other problems (like number crunching) the developer must create multiple threads, and ensure that those have as little interaction with other threads as possible. Implementing efficient parallel algorithms is hard.
 
aryan Sharma
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nitesh Kant wrote:
There are a lot of things that goes into scalability with additional processing power which a programmer should be aware of. Its not really as simple as it sounds.


This is what i want to know. is there any technical literature you can point to which suggests certain design guidelines....
 
Nitesh Kant
Bartender
Posts: 1638
IntelliJ IDE Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
aryan Sharma wrote:This is what i want to know. is there any technical literature you can point to which suggests certain design guidelines....


Well there is no holy grail for scalability. Everybody does it differently based on the kind of environment/architecture they have. You can read tons of articles on high scalability on what works for people.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic