php - 亚马逊AWS S3目录结构效率

标签 php amazon-web-services amazon-s3

我有一个简单的效率问题在我脑海中盘旋。

我创建了一个 PHP 代码,可以将我文件夹中的所有文件上传到我在 Amazon S3 上的存储桶。我的代码也能够在不丢失其结构的情况下上传子文件中的文件。

基本上,用户必须登录到我的网站,然后根据用户的帐户名,他们可以将照片上传到我在 Amazon s3 上的存储桶。用户最多可以上传 10 张照片 - 然后将这些照片修改为子文件类型,例如修改和缩略图。

我应该如何上传结构我的目录才能在 Amazon S3 上高效?

选项 1(文件在同一个存储桶但不同的文件夹中 - 更有条理)

username/originalfiles/picture01.jpg
username/original/picture02.jpg
username/original/picture03.jpg
....
username/original/picture10.jpg


username/modifiedpicture01.jpg
username/modified/picture02.jpg
username/modified/picture03.jpg
....
username/modified/picture10.jpg


username/thumbailspicture01.jpg
username/thumbails/picture02.jpg
username/thumbails/picture03.jpg
....
username/thumbails/picture10.jpg

或者

选项 2(同一存储桶中的所有文件)

username-original-picture01.jpg
username-original-picture02.jpg
username-original-picture03.jpg
....
username-original-picture10.jpg


username-modifiedpicture01.jpg
username-modified-picture02.jpg
username-modified-picture03.jpg
....
username-modified-picture10.jpg


username-thumbailspicture01.jpg
username-thumbails-picture02.jpg
username-thumbails-picture03.jpg
....
username-thumbails-picture10.jpg

或者它在 Amazon S3 中没有任何不同吗?

最佳答案

它对组织目的没有影响,S3 文件夹实际上只是一种幻觉,它对像我们这样的人有益,所以它看起来很熟悉——实际上没有像您自己的机器上那样的物理上独立的文件夹。

然而,您使用的命名约定会对性能产生巨大影响,一旦达到某个点(对于少量文件,它可能不会引起注意)。

一般来说,您希望文件/文件夹名称的开头部分是“随机的”,越随机越好...以便 s3 可以更好地分散工作量。如果名称前缀都相同,则会存在潜在的瓶颈。每个文件名开头的一个简短的随机散列可能会给你最好的性能。

就在马 (AWS) 的嘴里:

The sequence pattern in the key names introduces a performance problem. To understand the issue, let’s look at how Amazon S3 stores key names.

Amazon S3 maintains an index of object key names in each AWS region. Object keys are stored lexicographically across multiple partitions in the index. That is, Amazon S3 stores key names in alphabetical order. The key name dictates which partition the key is stored in. Using a sequential prefix, such as timestamp or an alphabetical sequence, increases the likelihood that Amazon S3 will target a specific partition for a large number of your keys, overwhelming the I/O capacity of the partition. If you introduce some randomness in your key name prefixes, the key names, and therefore the I/O load, will be distributed across more than one partition.

If you anticipate that your workload will consistently exceed 100 requests per second, you should avoid sequential key names. If you must use sequential numbers or date and time patterns in key names, add a random prefix to the key name. The randomness of the prefix more evenly distributes key names across multiple index partitions. Examples of introducing randomness are provided later in this topic.

http://docs.aws.amazon.com/AmazonS3/latest/dev/request-rate-perf-considerations.html

关于php - 亚马逊AWS S3目录结构效率,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22167125/

相关文章:

PHP 连接到 aws。连接被拒绝

ruby-on-rails-3 - 从一个 S3 读取图像并写入另一个 S3 时获取 Excon::Errors::SocketError?

php - 我使用phpinfo()获得的_ENV ["HTTP_X_VARNISH"]值是什么意思

php - Javascript 函数未定义

amazon-web-services - 从 NAT 实例后面的 AWS VPC 私有(private)子网进行 ftp 访问

c++ - 使用 C/C++ 访问 S3/DynamoDB 的选项

amazon-web-services - 将文件上传到 S3 的 upload() 和 putObject() 之间的区别?

php - 我需要我的系统获取系统当前时间

php - MySQL将玩家信息与时间连接起来

amazon-web-services - 属性安全组的值必须是字符串列表类型