【发布时间】:2016-03-02 00:08:01
【问题描述】:
我想更快地将 mp3 文件上传到我的 s3 存储桶。我正在使用this 捆。上传5MByte需要5分钟,太慢了。
public function labelAddSongAction($label){
$start = microtime(true);
$path = $this->request->files->get('file')->getRealPath();
$client = $this->get('aws.s3');
$aws_conn = microtime(true);
$song = $this->getDoctrine()->getRepository("WebsiteDeviceBundle:Labels")->addSong(
$label,
$this->request->get('title'),
$this->request->get('artist'),
$this->request->get('album'),
$this->request->get('genre'),
null,
$this->request->get('duration'),
$this->request->get('hash')
);
$db = microtime(true);
$result = $client->putObject(array(
'Bucket' => "bucket",
'Key' => 'masters-'.$song->getId().".".$this->request->files->get('file')->getClientOriginalExtension(),
'SourceFile' => $path
));
$putobj = microtime(true);
//dboperation with the result
$end = microtime(true);
die(
($aws_conn-$start)." aws conn<br>".
($db-$aws_conn)." db<br>".
($putobj-$db)." putobj<br>".
($end-$putobj)." db2<br>"
);
}
可以,但是太慢了。
这是死机时的输出(此尝试使用 3Mbyte 文件,因为更多,连接将超时)
0.018278121948242 aws 连接
0.014150857925415 分贝
2.4144551753998 putobj
0.0062119960784912 db2
我的 istance 在俄勒冈州(小实例),我的 s3 存储桶在爱尔兰。我从意大利上传(450kbps 上传)。直接从 aws 存储桶控制台上传相同的文件大约需要一分钟。
为了加快速度,您有什么建议? 将我的实例移至爱尔兰会显着改变上传时间吗? 升级实例然后移动它会更好吗?
【问题讨论】:
-
您可能希望通过在战略点记录一些时间戳来对此代码进行基准测试。如图所示,您似乎正在从意大利上传到俄勒冈州,并且在第一阶段完全完成后,实例正在从俄勒冈州上传到爱尔兰。哪个部分慢,第一部分还是第二部分?
-
@Michael-sqlbot 查看包含更多信息的编辑。看来第二个很慢
标签: php symfony amazon-web-services file-upload amazon-s3