I'm currently working on a big port with a lot of content (and growing):
- 1.2m users
- 900k nodes
- 400k files
Running a migration through drush is the only viable thing todo because the UI simple can't handle this. However, with such an amount, the migrate map and message tables fill quickly as well. The first 40k entries go relatively fast, but after that, you're in for a long wait. In case of my files migration, even after 12 hours it wasn't done (I suspect indexes on the source_hash_ids column)
I've been hacking around in MigrateUpgradeDrushRunner a bit and came up with following ideas and code (without hacking core so far) which made importing files run in around 70 minutes.
- if the number of items is bigger then a certain amount, start a new drush process in the background for a single migration plugin using an offset for the query, which is currently handled in migrate_upgrade_query_migrate_alter()
- after each process, move the records from map and message to a temporary table so new background process starts with a clean table (but from the right offset of course)
- there's a threshold for the amount of background processes, and new processes or new migrations won't start before all records from a plugin are processed
Note: code is still a bit rough so far (and will break for derivers like node), I will fix and cleanup (more helper methods and use config instead of constants) in the next couple of weeks and tackling another big problem, which is migration of users. The biggest single problem here is that the password hashing is awfully slow, so my idea is to swap out the user migrate plugin and defer the password hashing to a different plugin which can run after the users have been imported, in a different process. Eventually, this plugin can end up in core as well.
| Comment | File | Size | Author |
|---|---|---|---|
| #2 | 2708723-2.patch | 10.52 KB | swentel |
Comments
Comment #2
swentel commentedComment #3
swentel commentedComment #4
swentel commentedComment #5
swentel commentedComment #6
mikeryanSorry I haven't gotten around to look at this before. I have to say, it looks awfully complex, and potentially brittle (e.g. if it crashes the backup table data never gets merged back, does it?).
For a change of this complexity, I'd want to see more than a suspicion. The root issue in core here is #2688297: File migration slows down and eats more and more memory, eventually stops - what is badly needed there is someone experiencing the file migration slowdown to do some profiling with xhprof.
Comment #7
swentel commentedYeah, I need clean this up more, there's also to many duplicate code here - but it's running fine for now though .. :)
Comment #8
OnkelTem commentedWe have issues with memory leaks and severe speed degradation. Specifically, there are about 15000 source entities which are migrated into Drupal media entities (w/o files, they are in separate migration) and while at start it yields ~10 records per second, after some time the speed drops to 1 record per 5 seconds.
I couldn't figure out the reason or even find a place in the code where the leak occurs, so I also decided to just split migration into parts.
Initially I began to write a bash script but quickly realized that running it would be pain: it knows nothing about migrations dependencies, about drupal root, environment and other things. So I've switched to coding a drush command instead and then I found this issue. Will check it out and write back.
Comment #9
OnkelTem commentedSo I've create a drush command for running arbitrary migrations by parallel parts.
Now I'm getting a lots of DEADLOCKS and I don't really understand the reason of such locks.
Using MySQL InnoDB engine.
Example of such a lock:
Currently investigating the reason.
Comment #10
OnkelTem commentedCreated a sandboxed project Migrate Runner which can run migrations in batches and in parallel:
https://www.drupal.org/sandbox/onkeltem/2827995
It uses simple and sort of canonical strategy of avoiding deadlocks: transactions are restarted.
Welcome to give it a try.
Comment #11
heddnLet's incubate this in https://www.drupal.org/sandbox/onkeltem/2827995. Once we get some more experience with it, then let's see about merging back here.