Speed up the ls command for optimized listing performance
When you mount a bucket that contains a large number of objects or directories to a local file system, you can optimize the parameters in the mount operation to optimize object listing performance of the ls command.
Prerequisites
-
An Object Storage Service (OSS) bucket is created.
-
ossfs is installed.
Scenarios
-
The bucket contains a large number of objects or directories.
-
The bucket does not contain any existing symbolic links, and you do not intend to use the symbolic link feature later. Additionally, you do not require real-time updates of metadata such as the user ID (uid) and group ID (gid).
-
Metadata consistency is not a primary concern in, for example, model training or inference scenario. In these cases, files added to the dataset typically remain unchanged.
Parameters
|
Parameter |
Description |
|
max_stat_cache_size |
Specifies the maximum number of objects and directories whose metadata can be cached. In V1.91.x, this parameter defaults to 100000. The default setting requires approximately 40 MB of memory. In earlier versions, this parameter defaults to 1000. We recommend that you configure this parameter based on the number of frequently accessed objects in the bucket and the memory size. If the memory is sufficient, set this parameter to a reasonably large value (for example, 1000000) to have optimal performance.
|
|
readdir_optimize |
Specifies whether to use cache optimization. This parameter defaults to false. After you specify the parameter, ossfs does not send a HeadObject request to obtain the object metadata, such as |
|
stat_cache_expire |
Specifies whether to enable cache expiration or the cache validity period in seconds if cache expiration is enabled. This parameter defaults to 900 (15 minutes).
|
Mounting examples
-
Scenario 1: Mount a bucket that contains a large number of objects or directories
The following sample command mounts a bucket named
mybucketat the local/mnt/ossdirectory and caches the metadata of a maximum of 1,000,000 objects and directories (approximately 400 MB of memory).ossfs mybucket /mnt/oss -ourl=http://oss-cn-****.aliyuncs.com -omax_stat_cache_size=1000000 -
Scenario 2: Mount a bucket that contains no symbolic links in an application that does not involve the use of symbolic links later and does not require real-time updates of metadata such as the user ID (uid) and group ID (gid)
The following sample command mounts a bucket named
mybucketat the local/mnt/ossdirectory and disables sendingHeadObjectrequests in thelscommand.ossfs mybucket /mnt/oss -ourl=http://oss-cn-****.aliyuncs.com -oreaddir_optimize -
Scenario 3: Mount a bucket in a model training or inference scenario where metadata consistency is not a primary concern
The following sample command mounts a bucket named
mybucketat the local/mnt/ossdirectory with cache expiration disabled (stat_cache_expireset to -1). You can enable cache expiration by setting the stat_cache_expire parameter to a value greater than 0, for example, 72000 (cache expired in 20 hours).ossfs mybucket /mnt/oss -ourl=http://oss-cn-****.aliyuncs.com -ostat_cache_expire=-1