FAQ.Massive.txt 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358
  1. #!/bin/cat
  2. $Id: FAQ.Massive.txt,v 1.34 2022/07/14 16:00:23 gilles Exp gilles $
  3. This document is also available online at
  4. https://imapsync.lamiral.info/FAQ.d/
  5. https://imapsync.lamiral.info/FAQ.d/FAQ.Massive.txt
  6. =======================================================================
  7. Imapsync tips for massive/bulk migrations.
  8. =======================================================================
  9. Questions answered here are:
  10. Q. How long will take the whole migration?
  11. Q. I need to migrate hundreds of accounts, how can I do that?
  12. Q. I have to migrate 500k users using 400 TB of disk space.
  13. How do I proceed? How about speed?
  14. Q. How to determine where is the bottleneck in an imapsync process?
  15. Q. Can I run several instances of imapsync in parallel on a Windows host?
  16. Q. I run multiple imapsync applications at the same time and then get a
  17. warning "imapsync.pid already exists, overwriting it".
  18. Is this a potential problem when trying to sync multiple
  19. IMAP account in parallel?
  20. =======================================================================
  21. Q. How long will take the whole migration?
  22. R1. First, you have to consider several periods. There is the global
  23. period, from when the migration process is decided to the end,
  24. where all mailboxes are migrated. This global period can be divided
  25. into three smaller periods.
  26. The first period is the analysis period: you play with the tools
  27. available, you estimate the volume to be transferred, the number of
  28. accounts, you measure how long it takes for one account under
  29. your context.
  30. The second period is what I call the presyncing period.
  31. The users are still using
  32. the old accounts but nothing prevents you from starting to sync
  33. the old accounts, as they are, to the new accounts.
  34. With tons of gigabytes to transfer, this period may be the longest one.
  35. There is nothing more than launching the presyncs and monitoring them
  36. until the round is finished.
  37. The last period is the final sync period where only the last
  38. mailboxes' changes need to be synced before switching
  39. the users to their new mailboxes.
  40. R2. To estimate the presyncing period, consider the mean imapsync transfer
  41. rate to be around 340 Kbytes/s, ie, 2.8 Mbps, no matter the local
  42. link bandwidth.
  43. It's a mean, measured upon various syncs, coming from
  44. the online service /X where the network card flow rate is 200 Mbps
  45. (Rx 100 Mbps, Tx 100 Mbps) and the provider bandwidth is also 200 Mbps.
  46. The maximum global rate seen is 22 MiB/s (176 Mbps).
  47. At 340 Kbytes/s,
  48. 1 TB to transfer and one sync at a time will end in 35 days (1024^3/340/3600/24).
  49. At 10 transfers at a time, 1 TB will take 3.5 days.
  50. At 100 transfers at a time, 1 TB will take 8 hours.
  51. Double the time because the best scenario never happens.
  52. Triple the time because, well, the real world is like that.
  53. R3. Another way to better evaluate the end of the presyncing period can
  54. be based on your actual data. Just apply a simple rule of three
  55. on the mailboxes already migrated to estimate the global end.
  56. If it took X hours to finish Y% of the mailboxes, then it
  57. will take 100*X/Y hours to finish 100% of the mailboxes.
  58. Following the same idea but using mathematical garbage,
  59. the ETA can be estimated like this:
  60. t_0 = time of global start (the start of the first presync)
  61. t_now = time of now.
  62. Nb_total = total number of mailboxes to be migrated.
  63. Nb_now = number of mailboxes already migrated.
  64. then
  65. ETA = t_end = (t_now - t_0) * (Nb_total / Nb_now) + t_0
  66. R4. To estimate the last period, the final sync, just rerun a complete
  67. presync, ie, resync all the mailboxes, the final sync should take
  68. the same amount of time.
  69. =======================================================================
  70. Q. I need to migrate hundreds of accounts, how can I do that?
  71. R. If you have many mailboxes to migrate, think about a little
  72. script program. Write a file called file.txt (for example)
  73. containing hosts, users, and passwords on both sides.
  74. The separator used in this example is ";"
  75. The file.txt file contains for example:
  76. host001_1;user001_1;password001_1;host001_2;user001_2;password001_2;
  77. host002_1;user002_1;password002_1;host002_2;user002_2;password002_2;
  78. host003_1;user003_1;password003_1;host003_2;user003_2;password003_2;
  79. host004_1;user004_1;password004_1;host004_2;user004_2;password004_2;
  80. etc.
  81. Most of the time, the first column (host001_1, host002_1 ...) will
  82. contain the same value, the value of --host1 parameter. Same
  83. thing for the third column (host001_2, host002_2).
  84. On Unix the shell script can be:
  85. #!/bin/sh
  86. { while IFS=';' read h1 u1 p1 h2 u2 p2 fake
  87. do
  88. imapsync --host1 "$h1" --user1 "$u1" --password1 "$p1" \
  89. --host2 "$h2" --user2 "$u2" --password2 "$p2" "$@"
  90. done
  91. } < file.txt
  92. You can add extra options inside this script, just after the variable "$@".
  93. You can also pass extra options via the parameters of this script
  94. since they will go in "$@"
  95. Here is a complete Unix example ready to use:
  96. http://imapsync.lamiral.info/examples/sync_loop_unix.sh
  97. On Windows the batch script can be:
  98. CD /D %~dp0
  99. SET csvfile=file.txt
  100. FOR /F "tokens=1,2,3,4,5,6,7 delims=; eol=#" %%G IN (%csvfile%) DO (
  101. imapsync ^
  102. --host1 %%G --user1 %%H --password1 %%I ^
  103. --host2 %%J --user2 %%K --password2 %%L %%M ...
  104. )
  105. You can add extra options inside this script, just after the variable %%M.
  106. You can add extra options inside the file.txt, in the last column. Add
  107. an extra semicolon at the end (optional)
  108. Example:
  109. host001_1;user001_1;password001_1;host001_2;user001_2;password001_2;
  110. host002_1;user002_1;password002_1;host002_2;user002_2;password002_2;
  111. becomes
  112. host001_1;user001_1;password001_1;host001_2;user001_2;password001_2; --automap --addheader
  113. host002_1;user002_1;password002_1;host002_2;user002_2;password002_2; --automap --addheader
  114. With this solution, options can be added, changed, or removed per account.
  115. Technically those options will go in %%M in the loop body
  116. Here is a complete Windows example ready to use:
  117. http://imapsync.lamiral.info/examples/sync_loop_windows.bat
  118. Another solution to add extra arguments is to write another .bat that
  119. calls sync_loop_windows.bat with the extra arguments, like this
  120. for example:
  121. sync_loop_windows.bat --automap --addheader --maxmessagespersecond 4
  122. Technically those options will go in %arguments% in the loop body
  123. of sync_loop_windows.bat
  124. =======================================================================
  125. Q. I have to migrate 500k users using 400 TB of disk space.
  126. How do I proceed? How about speed?
  127. R. A good solution to this issue is two words: parallelism and measurements.
  128. Since all mailboxes are functionally independent, they can be processed
  129. independently, here comes the parallelism, ie, lunching several imapsync
  130. processes in parallel.
  131. Meanwhile, mailboxes usually belong to the same server, and the syncs
  132. share the same imapsync host via the same bandwidth, here come
  133. some limitations and bottlenecks.
  134. How many syncs can we run in parallel in your context?
  135. Here comes some measurements.
  136. 1) Measure the total transfer rate by adding each one printed in each run.
  137. Since adding this way is not so easy, just look at the overall
  138. network rate of the imapsync host.
  139. On Linux and FreeBSD, the command "nload" is a good candidate to measure this overall
  140. network rate. For example, to measure the rate every 6 seconds (-t 6000),
  141. on eth0 or em0 interface, with values in Kbytes (-u K), use:
  142. nload -t 6000 eth0 -u K # Linux
  143. nload -t 6000 em0 -u K # FreeBSD
  144. On Linux only, another very good network tool is dstat:
  145. dstat -n -N eth0 6 # Linux only (in 2018)
  146. Another excellent tool to measure the network traffic is iftop.
  147. The following command will monitor imap and imaps connections
  148. on interface eth0, only them, and sum them up:
  149. iftop -i eth0 -f 'port imap or port imaps' -B # Linux
  150. iftop -i em0 -f 'port imap or port imaps' -B # FreeBSD
  151. During iftop, press the h to see the display commands available,
  152. every single feature is useful! Press h again and try each one.
  153. My preferred display combination is by typing the keys
  154. t p >
  155. t means "one line per connection"
  156. p means "show port numbers"
  157. > means "sort by destination"
  158. On Windows 8.1 Windows 10 Windows 2012 R2 Windows 2016,
  159. get the overall network rate with the classical
  160. task manager (Ctrl-Shift-Esc), there is a Performance tab
  161. in it, where resides a Network monitor.
  162. On Windows 7, get the overall network rate with the classical
  163. task manager (Ctrl-Shift-Esc), there is a Network tab in it.
  164. I'm looking for a free and simple tool on Windows that could
  165. sum up only the imap traffic.
  166. 2) Launch new parallel runs, one by one, as long as the total
  167. transfer rate increase.
  168. 3) When the total transfer rate starts to diminish, stop new launches.
  169. Note N as the number of runs in parallel you got until then.
  170. 4) Only keep N-2 parallel runs for the future.
  171. =======================================================================
  172. Q. How to determine where is the bottleneck in an imapsync process?
  173. R1. Divide and conquer.
  174. To detect whether host1/link1 is the bottleneck or
  175. host2/link2, we have several tests to explore:
  176. 1) run a sync from host1 to host1, with a host1 test account as the destination.
  177. This way, only host1 and link1 are tested, host2 is not directly concerned.
  178. If performances increase a lot then host2/link2 is the bottleneck.
  179. 2) run a sync from host2 to host2, with a host2 test account as the destination.
  180. This way, only host2 and link2 are tested, host1 is not concerned.
  181. If performances increase a lot then host1/link1 is the bottleneck.
  182. If performances increase on both tests 1) and 2), I have no clue to explain that.
  183. Same thing if they both decrease!
  184. R2. Isolating and overcoming bottlenecks
  185. In any process involving several mechanisms, among all elements taking
  186. part in the process, there is always a bottleneck. No one knows in
  187. advance what is the first bottleneck. The first bottleneck has to be
  188. determined, by measurements, not by guesses. Once this first
  189. bottleneck is known and overcome then the next bottleneck has to be
  190. determined and overcome too, if needed. Repeat the process of looking
  191. for the next bottleneck and its elimination until you estimate the
  192. transfer rates, money costs, time spent on this, and final dates
  193. are good enough to proceed with the whole huge migration.
  194. Possible bottlenecks:
  195. - Throttles.
  196. IMAP servers have artificial limits.
  197. For example, Gmail, Office365, and Exchange have throttle limits.
  198. - Bandwidth.
  199. Usually, the available bandwidth is not a bottleneck.
  200. Meanwhile, it can be a bottleneck on small Internet connections.
  201. Imapsync downloads messages from host1 and upload messages to host2,
  202. consider this in case the connection is asymmetric.
  203. - I/O, aka "Input/Output" on the disks of the imap servers.
  204. The I/O on disks are a classical bottleneck, almost always forgotten.
  205. Unlike CPU and RAM, Input/Output performances don't improve
  206. very much as time goes on so it's often a bottleneck.
  207. To measure and overcome an I/O disk bottleneck, you need
  208. usually direct access to host1 and host2.
  209. An I/O bottleneck where imapsync runs is possible if
  210. --usecache or --useuid is used or with very big messages.
  211. - RAM.
  212. On all sides, monitor that your systems don't swap its
  213. running processes on disk, because swapping running processes
  214. on disks decreases performance by a factor of 20, at least.
  215. It's not because the swap memory is used that your
  216. system swaps processes on disk.
  217. - CPU.
  218. 100% CPU during a whole transfer means the system is busy.
  219. CPU can be a problem with imapsync but it can also be a problem
  220. with one or both of the imap servers.
  221. Other possible bottlenecks:
  222. - Number of hosts available to run imapsync processes.
  223. - Imapsync itself.
  224. - Management of errors.
  225. - MX domains, DNS.
  226. - Incompetence.
  227. - Money.
  228. - Time.
  229. - Bad luck.
  230. - ...
  231. =======================================================================
  232. Q. Can I run several instances of imapsync in parallel on a Windows host?
  233. R. Yes!
  234. Q. Any performance issues?
  235. You have to try and check the transfer rates, sum them up to
  236. have a unique numeric criterion.
  237. There is always a limit, depending on remote imap servers
  238. and the one running imapsync.
  239. CPU, memory, Inputs/Outputs are the classical bottlenecks,
  240. the worst bottleneck is the winner that sets the limit.
  241. examples/sync_loop_windows.bat says
  242. ...
  243. REM ==== Parallel executions ====
  244. REM If you want to do parallel runs of imapsync then this current script is a good start.
  245. REM Just copy it several times and replace, on each copy, the csvfile variable value.
  246. REM Instead of SET csvfile=file.txt write for example
  247. REM SET csvfile=file01.txt in the first copy
  248. REM then also
  249. REM SET csvfile=file02.txt in the second copy etc.
  250. REM Of course you also have to split the data contained in file.txt
  251. REM into file01.txt file02.txt etc.
  252. REM After that, just double-click on each batch file to launch each process
  253. =======================================================================
  254. Q. I run multiple imapsync applications at the same time and then get a
  255. warning "imapsync.pid already exists, overwriting it".
  256. Is this a potential problem when trying to sync multiple
  257. IMAP account in parallel?
  258. R1. No issue with the file imapsync.pid if you don't use its content
  259. by yourself.
  260. This file can help you to manage multiple runs by sending signals
  261. to the processes (sigterm or sigkill) using their PID.
  262. Each run can have its pid file with --pidfile option.
  263. The file imapsync.pid contains the PID of the current imapsync process.
  264. This file is removed at the end of a normal run.
  265. You can safely ignore the warning if you don't use imapsync.pid file
  266. to manage imapsync processes.
  267. =======================================================================
  268. =======================================================================