fsspec / fsspec/s3fs

Increase glob performance by utilizing prefixes

Open
#733 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
1k
Forks
305
Avg merge
22h 37m
Merged PRs (30d)
4

Description

Currently doing this results in a very poor query, listing every object (I think just in some-folder, but i have not looked too close) and then filtering in python.

fs.glob("s3://bucket-name/some-folder/some-file-*

Would it be possible to automatically add everything before the first wildcard as a prefix? Equivalent to

fs.find("s3://bucket-name/some-folder", prefix="some-file-")

I could imagine a more complex optimization here for when people use multiple * and **, but a cheap fix would help in a large number of use cases.

An real world example of running into this would be looking at cloudfront logs. AWS stores these in the format <user-controlled-directory>/<cloudfront-distribution-id>.%Y-%m-%d-%h-<random-int>.gz

If I wanted to work on a single day of these using s3fs + dask, the standard way would be

dd.read_csv("s3://bucket-name/logs/distributionid.2022-01-04-*")

Due to the way s3fs seems to be handling this, it results in paginating an potentially extremely large number of files (millions). My hacky workaround was to use find and run read_csv on each file individually, stitching them together with concat. Even this less than optimal workaround resulted in saving many minutes just paginating list results.

Dask or pandas could probably handle this upstream but i'm not sure that's the right place for this kind of optimization?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start from the fs.glob and fs.find entry points described in the issue, then trace how S3 listings are requested and filtered for wildcard paths. The change is done when a literal prefix before the first wildcard limits listing without changing glob results, including the shown CloudFront-log pattern; add or update coverage for these cases.

Written by the indexing model from the issue text.

Assessment

Tech stack
aws, python
Domain
cloud, performance
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.