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

Implement multiple queues. #1045

Merged
merged 28 commits into from
Oct 4, 2021
Merged

Implement multiple queues. #1045

merged 28 commits into from
Oct 4, 2021

Conversation

bastiencyr
Copy link
Collaborator

@bastiencyr bastiencyr commented Jul 27, 2021

Hello,
This PR will help me for #1005 . It is not ready yet since cancel button doesn't work anymore. Scheduler now has the ability to run jobs on multiple repositories concurrently and run multiple jobs on one repo (by queuing them).

In the future, all jobs will be copied into the db and run later if needed. It does not solve missed backup. It solves a fail backup (Power failure for example). I wait #1005 for this because #1005 change the db.

For each repository, there is one queue. I have represented a queue by a 'site'. Between sites (ie repository), tasks run concurrently. On one site, tasks run one by one.
The user also run tasks by adding them to the queue but he can't run multiple backups because start backup button is disabled when a job is running.

Related : #830

  • support for cancel jobs
  • check concurrent access (add mutex where necessary)
  • clean code
  • docs
  • pass tests
  • use simple queue instead of priority queue
  • rewrite enabled/disabled cancel button logic maybe with semaphore

@m3nu
Copy link
Contributor

m3nu commented Jul 27, 2021

Thanks for taking care! So this should be merged before or after #1005?

Since this is an essential feature, we should discuss it in detail before writing code. But testing different options is often needed of course.

My travels are almost done and I hope to get more involved again in the next days.

@bastiencyr
Copy link
Collaborator Author

bastiencyr commented Jul 27, 2021

Thanks for taking care! So this should be merged before or after #1005?

Before its better.

Since this is an essential feature, we should discuss it in detail before writing code. But testing different options is often needed of course.

I have no problem rewriting this code :)

My travels are almost done and I hope to get more involved again in the next days.

Enjoy your travel ;)

@bastiencyr
Copy link
Collaborator Author

bastiencyr commented Sep 4, 2021

Hello @m3nu ,
I added cancel support. There are some tests that don't pass anymore, it will be fix soon.

This is how the JobsManager looks like now (inspired from Command DP) :
JobsManager

When a Job is added to the JobsManager, the JobsManager sends this job to the right site which is a _Queue thanks to get_site_id. If the site _Queue does not exist, it is created by the JobsManager and _Queue starts immediatly a loop in a thread (threadpool) to handle jobs. The Job is then added to a python queue.
There is a timeout of 2 seconds on each site _Queue. After 2 seconds with an empty queue, the loop ends and the thread is free. The loop restarts if the JobsManager add a job to the site.

Actually, how the JobsManager handle Jobs is not relevant for the rest of the code. What is important is that you have a really simple interface to add a job to the JobsManager and your Job is encapsulated in an object which must provides get_site_id(), cancel() and run() function. It's very flexible if we want to change later how the JobsManager handle the job.

The running code of a Job must be in the run method. In the run method, you can launch a thread (QThread) but don't change the UI because run is itself launch in a thread. If you want to change the UI, you can use a signal/slot mechanism.

This new implementation makes BorgThread somewhat useless. The JobsManager already launch thread, so its a bit repetitive to launch a thread. Thats not matter for now and we can change this later.

Notice that Jobs run on multiple cores !

@bastiencyr
Copy link
Collaborator Author

bastiencyr commented Sep 7, 2021

Hello @m3nu , this PR is almost done and I dont expect any major implementation changes. I have updated my comment above.

@bastiencyr
Copy link
Collaborator Author

bastiencyr commented Sep 20, 2021

This new implementation makes BorgThread somewhat useless. The JobsManager already launch thread, so its a bit repetitive to launch a thread.

You can remove the inheritance from QThread for BorgThread and call it e.g. BorgJob, if threading is now done elsewhere. The main purpose of BorgThread is to prepare, run and post-process different Borg commands.

Fine I will try to remove the thread dependence.

So the user can only start one job at a time, but if there are multiple background jobs, they won't fail, but run after?

Yes The user have to wait that every jobs are finished to run a job and can run one job at a time. The manager tracks running job. The scheduler do whatever it wants, so if on 2 profiles you run backups on repo 1 and repo 2 at same time, the backup will be parallelized. If at the same time, a third profile run a backup on repo 1, the manager will just add this job to a queue to be run later.
You can make some performance tests, If you schedule backups on different profile on different repos , it will be faster than running these backups one by one (from the user for example).

@bastiencyr
Copy link
Collaborator Author

When a background job runs during a user-initiated backups, the "Start" button doesn't go back to enabled state. Probably the reason why one test is failing on the same check.

Screen Shot 2021-09-20 at 08 50 46

Is it happens with my last commit ? If so, you launch a backup on a different repo than the scheduler ?

@m3nu
Copy link
Contributor

m3nu commented Sep 20, 2021

Is it happens with my last commit ? If so, you launch a backup on a different repo than the scheduler ?

Yes, the latest commit 2bff7e8

Happened, when I had a backup from one profile running and another profile was scheduled, which ran after (or at the same time).

@bastiencyr bastiencyr closed this Sep 20, 2021
@bastiencyr bastiencyr reopened this Sep 20, 2021
@bastiencyr
Copy link
Collaborator Author

Is it happens with my last commit ? If so, you launch a backup on a different repo than the scheduler ?

Yes, the latest commit 2bff7e8

Happened, when I had a backup from one profile running and another profile was scheduled, which ran after (or at the same time).

Sorry I missclicked and closed the PR.

I cannot reproduce this. What I tried :
profile1: repo1 , 4GB to backup
profile2 : repo2 , 8GB to backup

  1. Schedule profile2 on repo2 for 19:10. Start profile1 on repo1 at 19:09. Works well.
  2. Remove archives. Schedule profile1 on repo1 for 19:10. Start profile2 on repo2 at 19:09. Works well.

@m3nu
Copy link
Contributor

m3nu commented Sep 22, 2021

Activity display in the taskbar also stops working with this PR. Should be orange, when a backup is active.

Screen Shot 2021-09-22 at 18 23 21

@bastiencyr
Copy link
Collaborator Author

bastiencyr commented Sep 23, 2021

Activity display in the taskbar also stops working with this PR. Should be orange, when a backup is active.

I dont have this bug too :( The method set_tray_icon in https://github.com/borgbase/vorta/blob/901992f026e2ddc968ec65430c2910fc6d657452/src/vorta/tray_menu.py is called with active=true on my laptop when I start a backup.

I will try to launch vorta on Ubuntu. I hope I can catch some bugs. For the moment, I dont have these bugs on Linux Mint and tests pass.

EDIT : I also had the bug on my laptop but I just not performed the right steps to reproduce. It should work now.
I will try to run on ubuntu anyway because I dont understand why tests don't pass on CI.

"original": trans_late("BorgThread", "Original"),
"deduplicated": trans_late("BorgThread", "Deduplicated"),
"compressed": trans_late("BorgThread", "Compressed"), }
self.category_label = {"files": trans_late("BorgJob", "Files"),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note to self: Update translations after renaming this.

@m3nu
Copy link
Contributor

m3nu commented Sep 29, 2021

Good progress. I'm liking this more and more.

There is still this random segfault in the test. FAILED tests/test_repo.py::test_repo_add_success. Probably an orphaned Qt object or something. It's a pain to get this right for the tests. I can look at that.

@bastiencyr
Copy link
Collaborator Author

Good progress. I'm liking this more and more.

<3

There is still this random segfault in the test. FAILED tests/test_repo.py::test_repo_add_success. Probably an orphaned Qt object or something. It's a pain to get this right for the tests. I can look at that.

I forget to add a job to the jobs_manager in repo_add_success and the job.run() method was directly run. But Im not sure to understand why it solves this issue. If I job.run() is called, there is no thread started like before. So the program block on this call.
Maybe, its linked to this line I removed : "self.thread = thread".
The commit that solved this is a78a615 , "Probably pass tests"

@m3nu
Copy link
Contributor

m3nu commented Sep 30, 2021

Nice! Seems to have fixed it.

I'll play with it a bit more and possibly fix minor bugs, like the icon that we saw.

Then we make a new branch v0.8.0, since this is a bigger change and we need to keep a maintenance branch of v0.7

@bastiencyr
Copy link
Collaborator Author

bastiencyr commented Sep 30, 2021

Nice! Seems to have fixed it.

I'll play with it a bit more and possibly fix minor bugs, like the icon that we saw.

Then we make a new branch v0.8.0, since this is a bigger change and we need to keep a maintenance branch of v0.7

Yes, Im glad that this PR is almost done ! After this I can back to #1005, the rebase will be a pain hh.
Will #1005 and #1008 also be in v0.8.0 ?

@m3nu
Copy link
Contributor

m3nu commented Sep 30, 2021

Will #1005 and #1008 also be in v0.8.0 ?

We should keep all large changes from here in a new branch. Mostly because Vorta is in Debian and they need to cherry-pick minor patches sometimes, but can't have too many changes. It also gives us time to properly develop a new major release without thinking about breaking stuff (as much).

@m3nu m3nu merged commit 54d8bbe into borgbase:master Oct 4, 2021
@m3nu
Copy link
Contributor

m3nu commented Oct 4, 2021

Thanks for this massive contribution! 👏 And sorry it took longer to merge it. I'm just wary of large PRs. I see you simplified a lot fo things and addressed all comments.

I've added a maintenance branch for the previous version v0.7 for adding small and urgent fixes. So we can keep doing larger changes in master. I'll also update the issue milestones to reflect this.

@bastiencyr
Copy link
Collaborator Author

Thanks for this massive contribution! clap And sorry it took longer to merge it. I'm just wary of large PRs. I see you simplified a > lot fo things and addressed all comments.

You're welcome.
No problem, it was good to take time. But there will be bugs and I will be there to fix it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants