2

I make parallel processing program using java.util.concurrent.ForkJoinPool. While proceeding this program, I checked top and htop, and noticed that in top there are only one java process but in htop there are many processes.

My senior is writing parallel processing program using python, and he says that it is strange that there are only one process in top. And also he says that the "CPU usage" in top is usually over 90%. But my program uses only about 68%.

I thought that the cause is the difference in how to realize parallel processing between java and python. But I do not know whether it is correct. Please tell me the correct cause of this difference.

Thanks.

tbt
  • 399
  • 3
  • 16
  • 1
    Maybe it's just because you do not do the same things in your code. But we can't tell since we can't see it... – vincrichaud Jun 26 '18 at 08:56
  • `top` does not show threads by default while `htop` does. You can use `top -H` and see what happens. It may be that the Python program uses processes rather than threads. I leave the difference between using threads to using processes to your research efforts. – RealSkeptic Jun 26 '18 at 09:00
  • I think we need to see your code. There are lots of *incorrect* ways to write parallel code in Java that will result in no effective parallelism. – Stephen C Jun 26 '18 at 09:10
  • >Mr. vincrichaud and Mr. Stephen Thanks for replying. I added source code link in my question. – tbt Jun 26 '18 at 09:14
  • >Mr. RealSkeptic Thanks for replying. I checked `top -H` and there are many **threads**. I'll research about parallel processing by using processes or threads. – tbt Jun 26 '18 at 09:17

1 Answers1

1

Did your senior implement multiprocessing or multithreading in python? To see the difference look at Multiprocessing vs Threading Python

I'm pretty sure he is doing multiprocessing, which spawns multiple processes which are real copy instead of threads with shared memory. The behavior of top/htop is correct. top only shows the processes while htop also shows the threads.

The difference would be that you are using multithreading and your senior seems to use multiprocessing also explains the different CPU usage.

You can press H in htop which will toggle the view of the user threads. Now it should be nearly the same view as in top.

Didier L
  • 18,905
  • 10
  • 61
  • 103
Bierbarbar
  • 1,399
  • 15
  • 35