01-12-2023, 11:29 PM
Language: Python 3.11
RoboDK version: 5.4.3
I have an application where I need to run SolveIK() many times (on the order of 10^8). To improve the speed, I am attempting to apply multithreading.
Using both 2 and 6 threads, I did not observe any performance improvement (in fact, it was slower). Additionally, in Windows resource monitor, I observed that no matter the number of threads, only 2 logical cores were utilized. However, console prints indicated that multiple threads were indeed running and making progress simultaneously. This leads me to believe that there is some issue preventing multiple SolveIK functions from running simultaneously.
Details:
- Each thread uses the -NEWINSTANCE flag and specifies a unique port to prevent multiple functions from calling the same instance of RoboDK.
- My machine has 32GB RAM and 16 logical cores
Here are my best guesses for the cause of the issue:
1. Something weird is happening with Python's GIL. However, since robolink.Robolink.SolveIK() just sends a command ("G_IK") to a library that was written in C, I am somewhat skeptical that the GIL is the problem.
2. There is some GIL-like thread lock object that is shared for all instances of RoboDK. I am not sure how to test this, except for asking the source-code authors.
3. A single call to SolveIK() returns fast enough that breaking out into multithreading is not faster. I would need to go back and write my own routine for batch-processing SolveIK() that is thread-safe and GIL-independent.
I suspect that (3) is the most likely cause of what I am seeing, but before I go to the effort of writing my own wrapper for SolveIK(), I wanted to get confirmation that there isn't something else going on that I can't solve.
If (3) is indeed the issue, would using the C API rather than the Python API fix my problem?
Thanks!
RoboDK version: 5.4.3
I have an application where I need to run SolveIK() many times (on the order of 10^8). To improve the speed, I am attempting to apply multithreading.
Using both 2 and 6 threads, I did not observe any performance improvement (in fact, it was slower). Additionally, in Windows resource monitor, I observed that no matter the number of threads, only 2 logical cores were utilized. However, console prints indicated that multiple threads were indeed running and making progress simultaneously. This leads me to believe that there is some issue preventing multiple SolveIK functions from running simultaneously.
Details:
- Each thread uses the -NEWINSTANCE flag and specifies a unique port to prevent multiple functions from calling the same instance of RoboDK.
- My machine has 32GB RAM and 16 logical cores
Here are my best guesses for the cause of the issue:
1. Something weird is happening with Python's GIL. However, since robolink.Robolink.SolveIK() just sends a command ("G_IK") to a library that was written in C, I am somewhat skeptical that the GIL is the problem.
2. There is some GIL-like thread lock object that is shared for all instances of RoboDK. I am not sure how to test this, except for asking the source-code authors.
3. A single call to SolveIK() returns fast enough that breaking out into multithreading is not faster. I would need to go back and write my own routine for batch-processing SolveIK() that is thread-safe and GIL-independent.
I suspect that (3) is the most likely cause of what I am seeing, but before I go to the effort of writing my own wrapper for SolveIK(), I wanted to get confirmation that there isn't something else going on that I can't solve.
If (3) is indeed the issue, would using the C API rather than the Python API fix my problem?
Thanks!