FreeCAD executable has excessive CPU usage during meshing

A subforum specific to the development of the OpenFoam-based workbenches ( Cfd https://github.com/qingfengxia/Cfd and CfdOF https://github.com/jaheyns/CfdOF )

Moderator: oliveroxtoby

Geefer
Posts: 17
Joined: Mon Feb 01, 2021 4:10 pm

FreeCAD executable has excessive CPU usage during meshing

Postby Geefer » Sat Mar 13, 2021 12:28 pm

During mesh creation the FreeCAD executable has excessive CPU usage even though it is mostly doing nothing apart from displaying the output from the mesh program and updating a timer for elapsed time. On my 4 core system one core is fully occupied with the mesh program as expected but another is totally occupied with the FreeCAD executable. (BTW is parallel meshing planned/possible? - UPDATE - I now realise it is but not enabled by default whereas it is with the solver)

I believe this is due to the calls of self.Timer.start() in file _TaskPanelCfdMesh.py.

The start method is being called with no parameter. The PySide.QtCore docs say:
PySide.QtCore.QTimer.start()
This function overloads PySide.QtCore.QTimer.start() .

Starts or restarts the timer with the timeout specified in PySide.QtCore.QTimer.interval() .
The docs for interval say:
PySide.QtCore.QTimer.interval()
Return type: PySide.QtCore.int
This property holds the timeout interval in milliseconds.

The default value for this property is 0. A PySide.QtCore.QTimer with a timeout interval of 0 will time out as soon as all the events in the window system’s event queue have been processed.
I have tried replacing calls

Code: Select all

self.Timer.start()
with

Code: Select all

self.Timer.start(100)
which explicitly sets the timeout to 100ms and reduces the CPU utilisation of the FreeCAD executable to a minimum. Setting the interval using

Code: Select all

PySide.QtCore.QTimer.setInterval(msec)
would be an alternative I guess.

I have only tried this on a Windows system as do not have FreeCAD on a Linux box at this time.

As a further note, the timer in _TaskPanelCfdSolverControl.py is never actually started so the timer update in the GUI is never updated when the solver is running.

Lastly it would be nice if the timer display was in the format h:mm:ss.s rather than s.s as for long runs it is harder to relate to several hundred seconds whereas a few minutes is easy to understand. Using datetime.timedelta() would achieve this partially, though it would show the decimal seconds part with too many decimal places without further processing. Using something like:

Code: Select all

str(timedelta(seconds=time.time() - self.Start))[:-5]
...might work.
User avatar
oliveroxtoby
Posts: 500
Joined: Fri Dec 23, 2016 9:43 am
Location: South Africa

Re: FreeCAD executable has excessive CPU usage during meshing

Postby oliveroxtoby » Sun Mar 14, 2021 4:21 pm

Geefer wrote: Sat Mar 13, 2021 12:28 pm During mesh creation the FreeCAD executable has excessive CPU usage even though it is mostly doing nothing apart from displaying the output from the mesh program and updating a timer for elapsed time. On my 4 core system one core is fully occupied with the mesh program as expected but another is totally occupied with the FreeCAD executable. (BTW is parallel meshing planned/possible? - UPDATE - I now realise it is but not enabled by default whereas it is with the solver)

I believe this is due to the calls of self.Timer.start() in file _TaskPanelCfdMesh.py.

The start method is being called with no parameter. The PySide.QtCore docs say:
PySide.QtCore.QTimer.start()
This function overloads PySide.QtCore.QTimer.start() .

Starts or restarts the timer with the timeout specified in PySide.QtCore.QTimer.interval() .
The docs for interval say:
PySide.QtCore.QTimer.interval()
Return type: PySide.QtCore.int
This property holds the timeout interval in milliseconds.

The default value for this property is 0. A PySide.QtCore.QTimer with a timeout interval of 0 will time out as soon as all the events in the window system’s event queue have been processed.
I have tried replacing calls

Code: Select all

self.Timer.start()
with

Code: Select all

self.Timer.start(100)
which explicitly sets the timeout to 100ms and reduces the CPU utilisation of the FreeCAD executable to a minimum. Setting the interval using

Code: Select all

PySide.QtCore.QTimer.setInterval(msec)
would be an alternative I guess.

I have only tried this on a Windows system as do not have FreeCAD on a Linux box at this time.

As a further note, the timer in _TaskPanelCfdSolverControl.py is never actually started so the timer update in the GUI is never updated when the solver is running.

Lastly it would be nice if the timer display was in the format h:mm:ss.s rather than s.s as for long runs it is harder to relate to several hundred seconds whereas a few minutes is easy to understand. Using datetime.timedelta() would achieve this partially, though it would show the decimal seconds part with too many decimal places without further processing. Using something like:

Code: Select all

str(timedelta(seconds=time.time() - self.Start))[:-5]
...might work.
Appreciate your work on this. I'll have a look when I have some time, but if you could open a pull request for these changes, that would be a big help.