如何单线程
canghaiwuhen opened this issue · 15 comments
比如ustc限制了单ip最多2个rsync线程,concurrent参数设置为1,单启动后还是有多个线程,导致同步失败
你说是concurrent设为1后还会同时运行多个rsync程序吗?如果这样的话那么是bug。
你说是concurrent设为1后还会同时运行多个rsync程序吗?如果这样的话那么是bug。
是的,还会有多个,一般2-4个
好的,我测试下这个场景
如果 rsync 作为接受文件的一方,每开启一个 rsync 任务,rsync 都会自行 fork 一次,您会在系统进程列表中看到两个 rsync 进程。因此如果看到了两个 rsync 进程,是正常现象。建议您提供一下您当前的配置,和出现此种现象时,htop 或 pstree 显示的树状的进程列表,以及同步任务输出的日志。
[[mirrors]]
name = "ubuntu"
concurrent = 1
interval = 240
rsync_timeout = 120
retry = 10
provider = "two-stage-rsync"
stage1_profile = "debian"
#upstream = "rsync://archive.ubuntu.com/ubuntu/"
upstream = "rsync://rsync.mirrors.ustc.edu.cn/repo/ubuntu/"
rsync_options = [ "--exclude *_hurd-i386.deb --delete-excluded" ]
memory_limit = "256M"
26181 pts/3 R 0:03 rsync -aHvh --no-o --no-g --stats --exclude .tmp/ --safe-links --exclude dists/ --timeout=120 rsync://rsync.mirrors.ustc.edu.cn/repo/ubuntu/ /opt/mirrors/web/ubuntu
26186 pts/3 S 0:00 rsync -aHvh --no-o --no-g --stats --exclude .tmp/ --safe-links --exclude dists/ --timeout=120 rsync://old-releases.ubuntu.com/old-releases/ubuntu/ /opt/mirrors/web/ubuntu-old-releases
26187 pts/3 S 0:00 rsync -aHvh --no-o --no-g --stats --exclude .tmp/ --safe-links --exclude dists/ --timeout=120 rsync://rsync.mirrors.ustc.edu.cn/repo/ubuntu/ /opt/mirrors/web/ubuntu
26190 pts/3 S 0:00 rsync -aHvh --no-o --no-g --stats --exclude .tmp/ --safe-links --exclude dists/ --timeout=120 rsync://old-releases.ubuntu.com/old-releases/ubuntu/ /opt/mirrors/web/ubuntu-old-releases
26196 pts/3 S+ 0:00 grep rsync
[20-06-12 13:48:27][NOTICE] start syncing: ubuntu
[20-06-12 13:48:32][NOTICE] start syncing: ubuntu-old-releases
[20-06-12 13:51:03][WARNIN] failed syncing ubuntu: exit status 1
[20-06-12 13:51:03][NOTICE] retry syncing: ubuntu, retry: 1
[20-06-12 13:53:28][WARNIN] failed syncing ubuntu: exit status 1
[20-06-12 13:53:28][NOTICE] retry syncing: ubuntu, retry: 2
[20-06-12 13:55:57][WARNIN] failed syncing ubuntu: exit status 1
[20-06-12 13:55:57][NOTICE] retry syncing: ubuntu, retry: 3
[20-06-12 13:58:21][WARNIN] failed syncing ubuntu: exit status 1
[20-06-12 13:58:21][NOTICE] retry syncing: ubuntu, retry: 4
[20-06-12 14:00:38][WARNIN] failed syncing ubuntu: exit status 1
[20-06-12 14:00:38][NOTICE] retry syncing: ubuntu, retry: 5
[20-06-12 14:03:09][WARNIN] failed syncing ubuntu: exit status 1
[20-06-12 14:03:09][NOTICE] retry syncing: ubuntu, retry: 6
[20-06-12 14:05:37][WARNIN] failed syncing ubuntu: exit status 1
[20-06-12 14:05:37][NOTICE] retry syncing: ubuntu, retry: 7
[20-06-12 14:08:09][WARNIN] failed syncing ubuntu: exit status 1
[20-06-12 14:08:09][NOTICE] retry syncing: ubuntu, retry: 8
[20-06-12 14:10:28][WARNIN] failed syncing ubuntu: exit status 1
[20-06-12 14:10:28][NOTICE] retry syncing: ubuntu, retry: 9
[20-06-12 14:12:57][WARNIN] failed syncing ubuntu: exit status 1
手动执行:
rsync -aHvh --no-o --no-g --stats --exclude .tmp/ --safe-links --exclude dists/ --timeout=120 rsync://rsync.mirrors.ustc.edu.cn/repo/ubuntu/ /opt/mirrors/web/ubuntu
不会报错,能正常同步
我发现你的concurrent放置的位置错了,应该在global节。参见 https://github.com/tuna/tunasync/blob/master/docs/zh_CN/workers.conf
您的配置有误,concorrent 参数是配置在 [global] 小节的,意思是同时最多进行的同步作业数目。修改该参数后,应该重新启动 worker 进程以便使该配置生效,reload 不能使该配置生效。
您的配置有误,concorrent 参数是配置在 [global] 小节的,意思是同时最多进行的同步作业数目。修改该参数后,应该重新启动 worker 进程以便使该配置生效,reload 不能使该配置生效。
[global]
name = "ubuntu_worker"
log_dir = "/opt/mirrors/tunasync/log/tunasync/{{.Name}}"
mirror_dir = "/opt/mirrors/web"
concurrent = 4
interval = 1
也放了,发现无效,就在各个单独的也放了
请您提供完整的配置文件,包括各个小节。以及 /opt/mirrors/tunasync/log/tunasync/
中的同步任务的日志。
[global]
name = "ubuntu_worker"
log_dir = "/opt/mirrors/tunasync/log/tunasync/{{.Name}}"
mirror_dir = "/opt/mirrors/web"
concurrent = 4
interval = 1
[manager]
api_base = "http://localhost:12345"
token = ""
ca_cert = ""
[cgroup]
enable = false
base_path = "/sys/fs/cgroup"
group = "tunasync"
[server]
hostname = "localhost"
listen_addr = "127.0.0.1"
listen_port = 6000
ssl_cert = ""
ssl_key = ""
[[mirrors]]
name = "ubuntu"
concurrent = 1
interval = 240
rsync_timeout = 120
retry = 10
provider = "two-stage-rsync"
stage1_profile = "debian"
#upstream = "rsync://archive.ubuntu.com/ubuntu/"
upstream = "rsync://rsync.mirrors.ustc.edu.cn/repo/ubuntu/"
rsync_options = [ "--exclude *_hurd-i386.deb --delete-excluded" ]
memory_limit = "256M"
[[mirrors]]
name = "ubuntu-ports"
concurrent = 1
interval = 240
rsync_timeout = 120
retry = 10
provider = "two-stage-rsync"
stage1_profile = "debian"
upstream = "rsync://ports.ubuntu.com/ubuntu-ports/"
#upstream = "rsync://rsync.mirrors.ustc.edu.cn/repo/ubuntu-ports/"
rsync_options = [ "--delete-excluded" ]
#exclude_file = "/etc/excludes/ubuntu-ports-exclude.txt"
memory_limit = "256M"
[[mirrors]]
name = "ubuntu-releases"
concurrent = 1
interval = 1440
rsync_timeout = 120
retry = 10
provider = "two-stage-rsync"
stage1_profile = "debian"
upstream = "rsync://rsync.releases.ubuntu.com/releases/"
rsync_options = [ "--delete-excluded" ] # delete .tmp folders
memory_limit = "256M"
[[mirrors]]
name = "ubuntu-old-releases"
concurrent = 1
interval = 1440
rsync_timeout = 120
retry = 100
provider = "two-stage-rsync"
stage1_profile = "debian"
upstream = "rsync://old-releases.ubuntu.com/old-releases/ubuntu/"
rsync_options = [ "--delete-excluded" ] # delete .tmp folders
memory_limit = "256M"
gogs:/opt/mirrors/tunasync/log/tunasync/ubuntu# vi ubuntu_2020-06-12_14_10.log.fail
| University of Science and Technology of China |
| Open Source Mirror (mirrors.ustc.edu.cn) |
|===============================================================|
| |
| We mirror a great many OSS projects & Linux distros. |
| |
| Currently we don't limit speed. To prevent overload, Each IP |
| is only allowed to start upto 2 concurrent rsync connections. |
| |
| This site also provides http/https/ftp access. |
| |
| Supported by USTC Network Information Center |
| and USTC Linux User Group (http://lug.ustc.edu.cn/). |
| |
| Sync Status: https://mirrors.ustc.edu.cn/status/ |
| News: https://servers.ustclug.org/ |
| Contact: lug@ustc.edu.cn |
| |
|_______________________________________________________________|
receiving incremental file list
pool/universe/libr/libreoffice/
Number of files: 971,619 (reg: 903,892, dir: 55,907, link: 11,820)
Number of created files: 0
Number of deleted files: 0
Number of regular files transferred: 0
Total file size: 1.31T bytes
Total transferred file size: 0 bytes
Literal data: 0 bytes
Matched data: 0 bytes
File list size: 30.21M
File list generation time: 0.001 seconds
File list transfer time: 0.000 seconds
Total bytes sent: 89.58K
Total bytes received: 36.43M
sent 89.58K bytes received 36.43M bytes 244.28K bytes/sec
total size is 1.31T speedup is 35,740.29
rsync: --exclude *_hurd-i386.deb --delete-excluded: unknown option
rsync error: syntax or usage error (code 1) at main.c(1585) [client=3.1.2]
rsync error: Syntax or usage error
看日志是--exclude *_hurd-i386.deb 这个参数不认
以前是用 rsync --links --hard-links --times --verbose --delete --recursive --exclude .tmp/ --exclude *_hurd-i386.deb rsync://rsync.mirrors.ustc.edu.cn/repo/ubuntu/ /opt/mirrors/web/ubuntu
这个命令做同步的
- 在 [[mirrors]] 小节中的 concurrent 没有用处,可以移除。
- 在 [global] 小节中,您统一指定了 interval =1,表示默认的同步频率是一分钟一次,但是在各个 [[mirrors]] 小节中,又覆盖了这一设定,因此您可以选择一个更加合理的默认值指定在 [global] 小节中。
- 在 [global] 小节中,指定了 concurrent=4,意味着同时可以有四个同步任务执行,您之前的需求是同时只能执行一个,因此需要调节为 1。但是由于您下面的各个 [[mirrors]] 中只有一个是从 ustc 同步的,因此无论 concurrent 设置为多少,应该不会触发 ustc 关于连接数的限制。
- rsync_options 应该传入一个数组,其数组的各个元素是附加传递给 rsync 的参数。您提供的 rsync 命令行中,
--exclude .~tmp~/ --exclude *_hurd-i386.deb
一共是四个参数,而在您的配置文件中只传入了一个参数,其内容是用空格分隔的四段文本,因此 rsync 不能正确识读。
- 在 [[mirrors]] 小节中的 concurrent 没有用处,可以移除。
- 在 [global] 小节中,您统一指定了 interval =1,表示默认的同步频率是一分钟一次,但是在各个 [[mirrors]] 小节中,又覆盖了这一设定,因此您可以选择一个更加合理的默认值指定在 [global] 小节中。
- 在 [global] 小节中,指定了 concurrent=4,意味着同时可以有四个同步任务执行,您之前的需求是同时只能执行一个,因此需要调节为 1。但是由于您下面的各个 [[mirrors]] 中只有一个是从 ustc 同步的,因此无论 concurrent 设置为多少,应该不会触发 ustc 关于连接数的限制。
- rsync_options 应该传入一个数组,其数组的各个元素是附加传递给 rsync 的参数。您提供的 rsync 命令行中,
--exclude .~tmp~/ --exclude *_hurd-i386.deb
一共是四个参数,而在您的配置文件中只传入了一个参数,其内容是用空格分隔的四段文本,因此 rsync 不能正确识读。
好的 谢谢
另外还有2个疑问 @shankerwangmiao
1、interval 设定是因为每个镜像的同步时间不一样,一个worker文件只能是同样时间间隔么
2、concurrent的设定是之前认为失败是rsync开的多线程,加入配置文件中有4个镜像,设定为10的话,会否开启多线程?