Skip to content

Commit

Permalink
prefetch: limit the amount of prefetches we have in flight to 2
Browse files Browse the repository at this point in the history
Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
  • Loading branch information
sahlberg committed Feb 10, 2015
1 parent ceb35bb commit 5f5faa8
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
16 changes: 13 additions & 3 deletions lib/libnfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -2103,8 +2103,6 @@ static void nfs_open_cb(struct rpc_context *rpc, int status, void *command_data,
nfsfh->fh = data->fh;
data->fh.data.data_val = NULL;

nfs_set_streaming_mode(nfsfh, 200 * NFS_STREAM_BUF_SIZE);

data->cb(0, nfs, nfsfh, data->private_data);
free_nfs_cb_data(data);
}
Expand Down Expand Up @@ -2374,12 +2372,24 @@ static void nfs_stream_cb(struct rpc_context *rpc, int status, void *command_dat

static void prefetch_streaming_blocks(struct nfs_context *nfs, struct nfsfh *nfsfh, uint64_t next_offset, int num_blocks)
{
int i;
int i, num_pending = 0;

for (i = 0; i < nfsfh->sr->num_blocks && num_blocks; i++) {
struct stream_cb_data *stream_data;
READ3args args;

/*
* BSS_PENDING means we have a request for prefetch in flight.
* We don't want an unlimited amount of requests in flight
* since it can cause wild latency spikes while initially
* filling the prefetch buffer.
*/
if (nfsfh->sr->blocks[i].state == BSS_PENDING) {
num_pending++;
}
if (num_pending >= num_blocks) {
continue;
}
if (nfsfh->sr->blocks[i].state != BSS_UNUSED) {
continue;
}
Expand Down
7 changes: 7 additions & 0 deletions nfs-stream.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ int main(int argc, char *argv[])
struct timeval t1, t2;
uint64_t delta, tpc;

if (argc != 3) {
fprintf(stderr, "Usage: nfs-stream <nfs-url> <bytes-per-second>\n");
exit(1);
}

nfs = nfs_init_context();
url = nfs_parse_url_full(nfs, argv[1]);
if (!url) {
Expand All @@ -36,6 +41,8 @@ int main(int argc, char *argv[])
nfs_get_error(nfs));
exit(1);
}
nfs_set_streaming_mode(nfsfh, 5 * 1024 * 1024);

if (nfs_fstat64(nfs, nfsfh, &st)) {
fprintf(stderr, "Failed to stat file %s: %s\n",
url->file,
Expand Down

0 comments on commit 5f5faa8

Please sign in to comment.