Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve performance with reduced execution time and lower CPU/system resource usage #2880

Merged
merged 4 commits into from
Oct 7, 2024

Conversation

abraunegg
Copy link
Owner

@abraunegg abraunegg commented Oct 4, 2024

  • Use global variables for logging verbose|debug logging state
  • Only perform debug logging steps including calculations and/or output if debugging is actually enabled
  • Optimise code execution and reduce resource usage by ~12% in real time, ~65% in CPU time, and ~87% in system time.

Calculations:

image

Command:

for i in {1..5}; do echo "Run #$i"; time ./onedrive -s --resync --resync-auth; echo ""; done

This PR shows significant improvements over 'master':

  • The real execution time is about 12.5% faster, meaning the overall process completes quicker.
  • The user time has decreased by nearly 65%, indicating that the new code base is more efficient in CPU utilisation.
  • The sys time has dropped by approximately 87%, which suggests the new code has reduced system overhead.

…resource usage

* Use global variables for logging verbose|debug logging state
* Only perform debug logging steps including calculations and/or output if debugging is actually enabled
* Optimise code execution and reduce resource usage by ~12% in real time, ~65% in CPU time, and ~87% in system time.
@abraunegg abraunegg added this to the v2.5.3 milestone Oct 4, 2024
@abraunegg
Copy link
Owner Author

abraunegg commented Oct 4, 2024

Master Flamegraph

flamegraph

PR Flamegraph - debug only fixed

flamegraph-pr2880

PR Flamegraph - verbose also fixed

flamegraph-pr2880-verbose

* Apply same change for --verbose
@abraunegg
Copy link
Owner Author

@bpozdena

Is there any opportunity for you to run your tests / use this PR for some feedback please ?

@bpozdena
Copy link

bpozdena commented Oct 5, 2024

@bpozdena

Is there any opportunity for you to run your tests / use this PR for some feedback please ?

I probably can, but I don't expect much of a difference in the actual sync cycle duration as I'm always heavily limited by the Graph API rate limit.

Will something like a graph of the CPU utilization for the onedrive process be enough for comparison?

@abraunegg
Copy link
Owner Author

@bpozdena
Is there any opportunity for you to run your tests / use this PR for some feedback please ?

I probably can, but I don't expect much of a difference in the actual sync cycle duration as I'm always heavily limited by the Graph API rate limit.

Will something like a graph of the CPU utilization for the onedrive process be enough for comparison?

Anything you can do would be greatly appreciated

@abraunegg abraunegg merged commit 576b46e into master Oct 7, 2024
1 check passed
@bpozdena
Copy link

bpozdena commented Oct 8, 2024

I noticed my system became very sluggish for several seconds with the new build. It's because I'm using 16 onedrive threads and most of them had very high CPU utilization. But I never noticed this behavior with the previous builds.

Unfortunately my original test did not monitor all CPU cores, so I have to re-do it again, which will take time.

Also the new build stopped before completing the sync with the bellow message without any additional details.

ERROR: Microsoft OneDrive API returned an error with the following message:
  Error Message:    HTTP request returned status code 400 (Bad Request)
  Error Reason:     Invalid request
  Error Code:       invalidRequest
  Calling Function: createLocalPathStructure()


Attempting to perform a database vacuum to optimise database
Database vacuum is complete

I will investigate all issues further, it just takes time because each resync cycle takes me over an hour to complete.

@abraunegg
Copy link
Owner Author

@bpozdena

I noticed my system became very sluggish for several seconds with the new build. It's because I'm using 16 onedrive threads and most of them had very high CPU utilization. But I never noticed this behavior with the previous builds.

Very ood I would say - as #2880 / 'master' - as all that PR does is less execution when not using --verbose or debug (double --verbose) ... essentially having less processing .. so I would say something very odd with that.

Also the new build stopped before completing the sync with the bellow message without any additional details.

If you can reproduce that at all - that would be good - i will go back and look at the change and see if I miss-edited something with that function specifically.

@bpozdena
Copy link

bpozdena commented Oct 8, 2024

  • The total re-sync time is always the same as it's mainly limited by the API response times.
  • The CPU utilization is noticeably improved in the non-verbose mode from average CPU utilization of 61% to 46%.
  • Unfortunately, there is a noticeable regression in the verbose mode (-v) from Average CPU utilization of 52% to 72%.

Non-verbose

v2.5.2 release - non-verbose resync with 12 threads:
Duration: 86 minutes
Average CPU utilization: 48%
Average CPU (idle excluded): 61%
plot_onedrive_CPU_252_non-verbose

v2.5.2-6-g59007d5 - non-verbose resync with 12 threads:
Duration: 83 minutes
Average CPU utilization: 36%
Average CPU (idle excluded): 46%
plot_onedrive_CPU_PR-non-verbose

Verbose (-v)

v2.5.2 release - verbose resync with 12 threads:
Duration: 84 minutes
Average CPU utilization: 40%
Average CPU (idle excluded): 52%
plot_onedrive_CPU_252_verbose

v2.5.2-6-g59007d5 - verbose resync with 12 threads:
Duration: 86 minutes
Average CPU : 57%
Average CPU (idle excluded): 72%
plot_onedrive_CPU_PR-verbose

@abraunegg abraunegg deleted the reduce-processing-overhead-if-not-debugging branch October 9, 2024 18:22
@abraunegg
Copy link
Owner Author

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Repository owner locked and limited conversation to collaborators Oct 17, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants