Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cache small blocks on the gateway seperately from responses #301

Open
hannahhoward opened this issue Jan 21, 2025 · 0 comments · May be fixed by storacha/freeway#147
Open

Cache small blocks on the gateway seperately from responses #301

hannahhoward opened this issue Jan 21, 2025 · 0 comments · May be fixed by storacha/freeway#147
Assignees

Comments

@hannahhoward
Copy link
Member

hannahhoward commented Jan 21, 2025

What

Our typical request pattern for data on the gateway looks like this: /ipfs/bafy...cid/somefile.txt (or bafy...cid.w3s.link/somefile.txt through w3s link). When we upload, even for individual files we wrap them in a folder with one item just so they can be addressed by name

This means the steps to get to first byte are as follows:

  1. o all content claims lookups to identify where we are pulling data from
  • then -
  1. Fetch cid bafy...cid which represents the folder containing somefile.txt, so that we can determine the verifiable cid for somefile.txt (let's call that bafy...file)
  2. Fetch cid bafy...file to get the root block of the file, which in UnixFS contains NO raw data, but rather is a list of sub-blocks that contain the file (let's call those bafy...bytes1 and bafy...bytes2)
  3. Finally, fetch the first raw data blocks, at which point we can finally send first byte.

Step 1 is a process we are trying optimize through the indexer.

2-4 however are 3 http roundtrips, which is just not realistic to get to first byte. Two of the round trips for typically small blocks that simply point us to the next link. It's made worse cause of #299, where some of those round trips are taking multiple seconds.

The proposed solution is as follows:
use cloudflare KV to cache these blocks or even better, simply the paths within them.

After first fetch, the following entry
Key: bafy...cid/somefile.txt/0-1000000
Value: baby...bytes1

Is sufficient to eliminate 2 of the 3 round trips on next request.

This should be relatively few lines of code but will require some knowledge of UnixFS, UnixFS exporter, and Dagula to do. Recommend if a newer dev is assigned that we pair with a experienced dev on repo guidance.

The KV should have a longer lifespan and eventually global distribution.

Acceptance criteria

Demonstrate traces in honeycomb

  • make a request with a typical 3 round trip requirement for the first time and take the typical 3 round trips to fetch data
  • make a second round trip request and verify only a single round trip is made before first bytes are sent

Note: you may need to disable caching of the whole request to demonstrate this behavior in test.

@hannahhoward hannahhoward converted this from a draft issue Jan 21, 2025
@fforbeck fforbeck self-assigned this Jan 22, 2025
@fforbeck fforbeck moved this from Sprint Backlog to In Progress in Storacha Project Planning Jan 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: In Progress
Development

Successfully merging a pull request may close this issue.

2 participants