Artifactspublic-v0

curl

master
ply4 git calls39 ms289 KiB3 cachedprotocol v2
113 lines4.8 KiBRaw
1#ifndef HEADER_CURL_RLIMIT_H
2#define HEADER_CURL_RLIMIT_H
3/***************************************************************************
4 * _ _ ____ _
5 * Project ___| | | | _ \| |
6 * / __| | | | |_) | |
7 * | (__| |_| | _ <| |___
8 * \___|\___/|_| \_\_____|
9 *
10 * Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
11 *
12 * This software is licensed as described in the file COPYING, which
13 * you should have received as part of this distribution. The terms
14 * are also available at https://curl.se/docs/copyright.html.
15 *
16 * You may opt to use, copy, modify, merge, publish, distribute and/or sell
17 * copies of the Software, and permit persons to whom the Software is
18 * furnished to do so, under the terms of the COPYING file.
19 *
20 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
21 * KIND, either express or implied.
22 *
23 * SPDX-License-Identifier: curl
24 *
25 ***************************************************************************/
26#include "curlx/timeval.h"
28struct Curl_easy;
30#define CURL_US_PER_SEC 1000000
32/* This is a rate limiter that provides "tokens" to be consumed
33 * per second. In the literature, this is referred to as a
34 * "token bucket" (https://en.wikipedia.org/wiki/Token_bucket).
35 * Example:
36 * A rate limit of 1 megabyte per second.
37 * - initially 1 million tokens are available.
38 * - these are drained in the first second.
39 * - checking available tokens before the 2nd second will return 0.
40 * - at/after the 2nd second, 1 million tokens are available again.
41 * - nothing happens for a second, the 1 million tokens would grow
42 * to 2 million, however the burst limit caps those at 1.5 million.
43 * Thus:
44 * - setting "burst" to CURL_OFF_T_MAX would average tokens over the
45 * complete lifetime. E.g. for a download, at the *end* of it, the
46 * average rate from start to finish would be the rate limit.
47 * - setting "burst" to the same value as "rate" would make a
48 * download always try to stay *at/below* the rate and slow times will
49 * not generate extra tokens.
50 *
51 * A rate limit can be blocked, causing the available tokens to become
52 * always 0 until unblocked. After unblocking, the rate limiting starts
53 * again with no history of the past.
54 *
55 * Finally, a rate limiter with rate 0 will always have CURL_OFF_T_MAX
56 * tokens available, unless blocked.
57 */
59struct Curl_rlimit {
60 int64_t rate_per_sec; /* rate tokens generated per second */
61 int64_t burst_per_sec; /* burst rate of tokens per second */
62 int64_t rate_per_step; /* rate tokens generated per step us */
63 int64_t burst_per_step; /* burst rate of tokens per step us */
64 timediff_t step_us; /* microseconds between token increases */
65 int64_t tokens; /* tokens available in the next second */
66 timediff_t spare_us; /* microseconds unaffecting tokens */
67 struct curltime ts; /* time of the last update */
68 BIT(blocked); /* blocking sets available tokens to 0 */
69};
71/* Start ratelimiting with the given timestamp. Resets available tokens.
72 * `total_tokens` is either -1 or the number of total tokens expected
73 * to be consumed. */
74/* Change the rates of a limiter that may be in use. Keeps the blocked
75 * state and the time already accounted for, caps the tokens at the new
76 * rate. */
77void Curl_rlimit_change(struct Curl_rlimit *r,
78 int64_t rate_per_sec,
79 int64_t burst_per_sec);
81void Curl_rlimit_start(struct Curl_rlimit *r, const struct curltime *pts,
82 int64_t total_tokens);
84/* How many milliseconds to wait until token are available again. */
85timediff_t Curl_rlimit_wait_ms(struct Curl_rlimit *r,
86 const struct curltime *pts);
88/* When the rate limit will update its tokens again */
89timediff_t Curl_rlimit_next_step_ms(struct Curl_rlimit *r,
90 const struct curltime *pts);
92/* Return if rate limiting of tokens is active */
93bool Curl_rlimit_active(struct Curl_rlimit *r);
94bool Curl_rlimit_is_blocked(struct Curl_rlimit *r);
95int64_t Curl_rlimit_per_step(struct Curl_rlimit *r);
97/* Return how many tokens are available to spend, may be negative.
98 * Pass timestamp or NULL. */
99int64_t Curl_rlimit_avail(struct Curl_rlimit *r,
100 const struct curltime *pts);
102/* Drain tokens from the ratelimit, give an estimate of how many tokens
103 * remain to be drained in the future (-1 for unknown).
104 * Pass timestamp or NULL. */
105void Curl_rlimit_drain(struct Curl_rlimit *r, size_t tokens,
106 const struct curltime *pts);
108/* Block/unblock ratelimiting. A blocked ratelimit has 0 tokens available. */
109void Curl_rlimit_block(struct Curl_rlimit *r,
110 bool activate,
111 const struct curltime *pts);
113#endif /* HEADER_CURL_RLIMIT_H */
Diagnostics4 git calls · 39 ms
CallStatusSizeTime039 ms
discover200152 B2 ms
git.upload-pack discover
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=ls-refs
git.upstream.dur_ms=2
git.response.bytes=152
git.server.agent=gitty/1.0
git.server.object_format=sha1
git.server.caps=agent ls-refs fetch object-format
git.server.fetch=shallow filter sideband-all
git.protocol.version=2
git.pkt.frames=8
git.pkt.data=6
git.pkt.flush=2
git.pkt.delim=0
git.pkt.bytes=152
git.pkt.payload.max=34
ls-refs200149 B · hit3 ms
git.upload-pack ls-refs
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=ls-refs
git.upstream.dur_ms=3
git.response.bytes=149
git.response.cache=HIT
git.response.duration_ms=3
git.protocol.version=2
git.pkt.frames=3
git.pkt.data=2
git.pkt.flush=1
git.pkt.delim=0
git.pkt.bytes=149
git.pkt.payload.max=78
git.ls_refs.count=2
git.ls_refs.head=refs/heads/master
fetchblob:none · deepen 10200287 KiB · hit3 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=3
git.response.bytes=293470
git.response.cache=HIT
git.response.duration_ms=3
git.fetch.filter=blob:none
git.fetch.filter.requested=tree:0
git.fetch.filter.fallback=blob:none
git.fetch.filter.learned=false
git.fetch.wants=31c911efe5652725e930f4d2e60c9060e5f6646d
git.fetch.haves.count=0
git.fetch.deepen=10
git.fetch.thin_pack=false
git.fetch.ofs_delta=true
git.protocol.version=2
git.pkt.frames=10
git.pkt.data=8
git.pkt.flush=1
git.pkt.delim=1
git.pkt.bytes=293470
git.pkt.payload.max=65516
git.sideband.band1.bytes=293354
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0
git.pack.objects=87
git.pack.bytes=293354
git.pack.ofs_delta=0
git.pack.ref_delta=1
git.pack.chain.max=1
git.pack.trailer=6a646bcda6740bab42e321b51998b52ea15146c0
git.pack.full=86
Open pack map
fetch2001.8 KiB · hit33 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=32
git.response.bytes=1844
git.response.cache=HIT
git.response.duration_ms=33
git.fetch.wants=3969009bf472cce89e77b727edc47cdb38abcb0e
git.fetch.haves.count=0
git.fetch.deepen=0
git.fetch.thin_pack=false
git.fetch.ofs_delta=true
git.protocol.version=2
git.pkt.frames=3
git.pkt.data=2
git.pkt.flush=1
git.pkt.delim=0
git.pkt.bytes=1844
git.pkt.payload.max=1823
git.sideband.band1.bytes=1822
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0

Each row is one HTTP round trip ply made to the git server for this page, on one timeline. discover asks what the server speaks, ls-refs lists branch tips, fetch brings objects by id. A hit was served by Workers Cache. Tap a row for its wire details.

Remote
https://5ad2236b39de4c8bd8f6270ea63f3ea9.artifacts.cloudflare.net/git/public-v0/curl.git
Ref
refs/heads/master
Commit
31c911efe5652725e930f4d2e60c9060e5f6646d
cf-ray
a5e2d08e3ce3efad
Request
bc901c12…
Protocol
v2 · sha1
Agent
gitty/1.0
Filter
advertised
Fetch
shallow filter sideband-all
Capabilities
agent ls-refs fetch object-format