You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@pekko.apache.org by "yahyashqair (via GitHub)" <gi...@apache.org> on 2024/03/23 21:28:05 UTC

[D] visualVM CPU usage of Unsafe.unpark [pekko]

GitHub user yahyashqair created a discussion: visualVM CPU usage of Unsafe.unpark

Hi guys, 
I am debugging a system was built on top of akka 2.6.. and the system has mainly two dispatchers
1- default dispatcher. 
2- JDBC dispatcher that uses blocking API. (50 Threads pool size)
and the cpu has two cores.
![image](https://github.com/apache/pekko/assets/37252929/30c33051-9e16-4a56-9c65-7d1aedd4d222)
As you can see in the image unpark method takes too much time in the CPU! why? and how can i fix it.


GitHub link: https://github.com/apache/pekko/discussions/1222

----
This is an automatically sent email for notifications@pekko.apache.org.
To unsubscribe, please send an email to: notifications-unsubscribe@pekko.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org
For additional commands, e-mail: notifications-help@pekko.apache.org


Re: [D] visualVM CPU usage of Unsafe.unpark [pekko]

Posted by "pjfanning (via GitHub)" <gi...@apache.org>.
GitHub user pjfanning added a comment to the discussion: visualVM CPU usage of Unsafe.unpark

It is often recommended to use ThreadPoolExecutors for blocking code as opposed to ForkJoinPools.

The Dispatcher settings in Akka and Pekko are quite configurable. Try playing around with various settings.

GitHub link: https://github.com/apache/pekko/discussions/1222#discussioncomment-8891528

----
This is an automatically sent email for notifications@pekko.apache.org.
To unsubscribe, please send an email to: notifications-unsubscribe@pekko.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org
For additional commands, e-mail: notifications-help@pekko.apache.org


Re: [D] visualVM CPU usage of Unsafe.unpark [pekko]

Posted by "He-Pin (via GitHub)" <gi...@apache.org>.
GitHub user He-Pin added a comment to the discussion: visualVM CPU usage of Unsafe.unpark

Which means you are using too much blocking code.

GitHub link: https://github.com/apache/pekko/discussions/1222#discussioncomment-8890825

----
This is an automatically sent email for notifications@pekko.apache.org.
To unsubscribe, please send an email to: notifications-unsubscribe@pekko.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org
For additional commands, e-mail: notifications-help@pekko.apache.org


Re: [D] visualVM CPU usage of Unsafe.unpark [pekko]

Posted by "He-Pin (via GitHub)" <gi...@apache.org>.
GitHub user He-Pin edited a comment on the discussion: visualVM CPU usage of Unsafe.unpark

I'm not sure your case, but at $work, I'm using Source.queue which introduces a nonblocking queue for task sharing.

GitHub link: https://github.com/apache/pekko/discussions/1222#discussioncomment-8896973

----
This is an automatically sent email for notifications@pekko.apache.org.
To unsubscribe, please send an email to: notifications-unsubscribe@pekko.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org
For additional commands, e-mail: notifications-help@pekko.apache.org


Re: [D] visualVM CPU usage of Unsafe.unpark [pekko]

Posted by "yahyashqair (via GitHub)" <gi...@apache.org>.
GitHub user yahyashqair added a comment to the discussion: visualVM CPU usage of Unsafe.unpark

Thank you all. I'd like to share some findings. I experimented with ThreadPoolExecutors for JDBC, along with ForkJoinPools for Redis/Akka internals/Scala futures, and regular actors.

As we know, blocking operations should be avoided in Akka/Pekko or any reactive system. When submitting tasks between two dispatchers using ForkJoinPools, the signalExternal() and unpark() methods are invoked – these are blocking operations that consume time.  My goal was to find a way to avoid triggering unpark(). I discovered that submitting tasks within the same ForkJoinExecutor eliminates the need for unpark(), improving efficiency. Consequently, I unified all non-blocking executors into a single one, and this successfully reduced CPU overhead caused by unpark().

However, the JDBC integration prevents me from merging its dispatcher with the non-blocking one. To address this, I'm considering using Project Loom on the JDBC executor and ultimately unifying all executors into a single entity.

What are your thoughts on this approach?"

GitHub link: https://github.com/apache/pekko/discussions/1222#discussioncomment-8895549

----
This is an automatically sent email for notifications@pekko.apache.org.
To unsubscribe, please send an email to: notifications-unsubscribe@pekko.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org
For additional commands, e-mail: notifications-help@pekko.apache.org


Re: [D] visualVM CPU usage of Unsafe.unpark [pekko]

Posted by "He-Pin (via GitHub)" <gi...@apache.org>.
GitHub user He-Pin added a comment to the discussion: visualVM CPU usage of Unsafe.unpark

I'm not sure your case, but at $work, I'm using Source.queue which introduce a nonblocking queue for task sharing.

GitHub link: https://github.com/apache/pekko/discussions/1222#discussioncomment-8896973

----
This is an automatically sent email for notifications@pekko.apache.org.
To unsubscribe, please send an email to: notifications-unsubscribe@pekko.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org
For additional commands, e-mail: notifications-help@pekko.apache.org


Re: [D] visualVM CPU usage of Unsafe.unpark [pekko]

Posted by "yahyashqair (via GitHub)" <gi...@apache.org>.
GitHub user yahyashqair added a comment to the discussion: visualVM CPU usage of Unsafe.unpark

@laglangyue I will give it a try in the future. 
@He-Pin 
If i understand you correctly. Here I am not talking about submitting tasks using ask or tell pattern.
assume we have two dispatcher(executor services).
and we have this kind of logic
`
Future {
  // some logic
  Future {callDB} (dbExecutor)
  // some logic
}(futureExecutor)
`
Here I am submitting a task to dbExecutor and it will be using some kind of locking which will call unpark and park. 
So what can i do here to prevent this kind of blocking. and as I understand you. If i use "tell or ask" pattern, It will not do parking? 

GitHub link: https://github.com/apache/pekko/discussions/1222#discussioncomment-8900771

----
This is an automatically sent email for notifications@pekko.apache.org.
To unsubscribe, please send an email to: notifications-unsubscribe@pekko.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org
For additional commands, e-mail: notifications-help@pekko.apache.org


Re: [D] visualVM CPU usage of Unsafe.unpark [pekko]

Posted by "laglangyue (via GitHub)" <gi...@apache.org>.
GitHub user laglangyue added a comment to the discussion: visualVM CPU usage of Unsafe.unpark

Interesting! As a Engineer,I just support some ideas. Maybe you can try java21 Virtual Thread with pekko.

GitHub link: https://github.com/apache/pekko/discussions/1222#discussioncomment-8896924

----
This is an automatically sent email for notifications@pekko.apache.org.
To unsubscribe, please send an email to: notifications-unsubscribe@pekko.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org
For additional commands, e-mail: notifications-help@pekko.apache.org


Re: [D] visualVM CPU usage of Unsafe.unpark [pekko]

Posted by "laglangyue (via GitHub)" <gi...@apache.org>.
GitHub user laglangyue added a comment to the discussion: visualVM CPU usage of Unsafe.unpark

`Unpark` and `park` methods occupy too much CPU, indicating that your thread context switches too frequently.

GitHub link: https://github.com/apache/pekko/discussions/1222#discussioncomment-8890683

----
This is an automatically sent email for notifications@pekko.apache.org.
To unsubscribe, please send an email to: notifications-unsubscribe@pekko.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org
For additional commands, e-mail: notifications-help@pekko.apache.org


Re: [D] visualVM CPU usage of Unsafe.unpark [pekko]

Posted by "yahyashqair (via GitHub)" <gi...@apache.org>.
GitHub user yahyashqair added a comment to the discussion: visualVM CPU usage of Unsafe.unpark

After using Async-profiler. I saw that the unpark method doesn't use CPU. Most probably it is an issue with VisualVM. 

GitHub link: https://github.com/apache/pekko/discussions/1222#discussioncomment-9244220

----
This is an automatically sent email for notifications@pekko.apache.org.
To unsubscribe, please send an email to: notifications-unsubscribe@pekko.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org
For additional commands, e-mail: notifications-help@pekko.apache.org