2013年1月12日

s3cmd 檔案傳輸速度調校筆記

在 Linux 與 Mac OS X 的開發環境,我使用 s3cmd 這個工具,將完成的檔案佈署發佈到 S3 Bucket。

s3cmd tool
http://s3tools.org/s3cmd

在 Ubuntu Linux 及 Mac OS X + MacPorts 下安裝 s3cmd 很容易。

sudo apt-get install s3cmd



sudo port install s3cmd

然後設定 AWS 的 SECRET KEY 就可以開使用。

因為這個工具透過 Web Service 存取 AWS / S3,新版本在速度上有設限制。由於最近使用頻率很高,但傳輸速度慢的問題實在造成很大困擾 : )

我的檔案大小 75MB。

$ du -h target/codecanaan.war
75M target/codecanaan.war

網路頻寬則是 HINET 光世代固定制 50M / 20M。

若以預設值上傳,真是等到天荒地老...

$ s3cmd put -P target/codecanaan.war s3://s3.xxxxxx.com/apps/
target/codecanaan.war -> s3://s3.xxxxxx.com/apps/codecanaan.war  [part 1 of 5, 15MB]
 15728640 of 15728640   100% in  107s   142.89 kB/s  done
target/codecanaan.war -> s3://s3.xxxxxx.com/apps/codecanaan.war  [part 2 of 5, 15MB]
 15728640 of 15728640   100% in  106s   144.39 kB/s  done
target/codecanaan.war -> s3://s3.xxxxxx.com/apps/codecanaan.war  [part 3 of 5, 15MB]
 15728640 of 15728640   100% in  110s   139.12 kB/s  done
target/codecanaan.war -> s3://s3.xxxxxx.com/apps/codecanaan.war  [part 4 of 5, 15MB]
 15728640 of 15728640   100% in  109s   140.87 kB/s  done
target/codecanaan.war -> s3://s3.xxxxxx.com/apps/codecanaan.war  [part 5 of 5, 14MB]
 15473658 of 15473658   100% in  104s   145.20 kB/s  done
Public URL of the object is: http://s3.xxxxxx.com.s3.amazonaws.com/apps/codecanaan.war

在設定檔 ~/.s3cfg 找到速度慢的兇手:

recv_chunk = 4096
send_chunk = 4096

上傳檔案只要調整 send_chunk,設定成 4096 * 16 = 65536

recv_chunk = 4096
send_chunk = 65536

調校後,速度真是天差地遠阿!

$ s3cmd put -P target/codecanaan.war s3://s3.xxxxxx.com/apps/
target/codecanaan.war -> s3://s3.xxxxxx.com/apps/codecanaan.war  [part 1 of 5, 15MB]
 15728640 of 15728640   100% in   13s  1163.89 kB/s  done
target/codecanaan.war -> s3://s3.xxxxxx.com/apps/codecanaan.war  [part 2 of 5, 15MB]
 15728640 of 15728640   100% in   13s  1148.22 kB/s  done
target/codecanaan.war -> s3://s3.xxxxxx.com/apps/codecanaan.war  [part 3 of 5, 15MB]
 15728640 of 15728640   100% in   14s  1032.15 kB/s  done
target/codecanaan.war -> s3://s3.xxxxxx.com/apps/codecanaan.war  [part 4 of 5, 15MB]
 15728640 of 15728640   100% in   12s  1273.37 kB/s  done
target/codecanaan.war -> s3://s3.xxxxxx.com/apps/codecanaan.war  [part 5 of 5, 14MB]
 15473658 of 15473658   100% in   18s   805.14 kB/s  done
Public URL of the object is: http://s3.xxxxxx.com.s3.amazonaws.com/apps/codecanaan.war

預設會將大型檔案切割成每塊(chunk part) 15MB 的大小,會讓速度沒辦法拉到應有水準,這問題可以加上 --multipart-chunk-size-mb=100 解決。

$ s3cmd put --multipart-chunk-size-mb=100 -P target/codecanaan.war s3://s3.xxxxxx.com/apps/
target/codecanaan.war -> s3://s3.lyhdev.com/apps/codecanaan.war  [1 of 1]
 78388218 of 78388218   100% in   56s  1345.77 kB/s  done
Public URL of the object is: http://s3.xxxxxx.com.s3.amazonaws.com/apps/codecanaan.war

增加 send_chunk 的值可以讓傳輸更快,但是設定太高會有反效果,容易導致傳輸失敗(或速度不增反減)。

沒有留言:

張貼留言

lyhcode by lyhcode
歡迎轉載,請務必註明出處!