master
1/***************************************************************************
2 * _ _ ____ _
3 * Project ___| | | | _ \| |
4 * / __| | | | |_) | |
5 * | (__| |_| | _ <| |___
6 * \___|\___/|_| \_\_____|
7 *
8 * Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
9 *
10 * This software is licensed as described in the file COPYING, which
11 * you should have received as part of this distribution. The terms
12 * are also available at https://curl.se/docs/copyright.html.
13 *
14 * You may opt to use, copy, modify, merge, publish, distribute and/or sell
15 * copies of the Software, and permit persons to whom the Software is
16 * furnished to do so, under the terms of the COPYING file.
17 *
18 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19 * KIND, either express or implied.
20 *
21 * SPDX-License-Identifier: curl
22 *
23 ***************************************************************************/
24/* <DESC>
25 * Download many files in parallel, in the same thread.
26 * </DESC>
27 */
28#include <stdlib.h>
29#include <string.h>
31#include <curl/curl.h>
33static const char * const urls[] = {
34 "https://01.example/",
35 "https://02.example/",
36 "https://03.example/",
37 "https://04.example/",
38 "https://05.example/",
39 "https://06.example/",
40 "https://07.example/",
41 "https://08.example/",
42 "https://09.example/",
43 "https://10.example/",
44 "https://11.example/",
45 "https://12.example/",
46 "https://13.example/",
47 "https://14.example/",
48 "https://15.example/",
49 "https://16.example/",
50 "https://17.example/",
51 "https://18.example/",
52 "https://19.example/",
53 "https://20.example/",
54 "https://21.example/",
55 "https://22.example/",
56 "https://23.example/",
57 "https://24.example/",
58 "https://25.example/",
59 "https://26.example/",
60 "https://27.example/",
61 "https://28.example/",
62 "https://29.example/",
63 "https://30.example/",
64 "https://31.example/",
65 "https://32.example/",
66 "https://33.example/",
67 "https://34.example/",
68 "https://35.example/",
69 "https://36.example/",
70 "https://37.example/",
71 "https://38.example/",
72 "https://39.example/",
73 "https://40.example/",
74 "https://41.example/",
75 "https://42.example/",
76 "https://43.example/",
77 "https://44.example/",
78 "https://45.example/",
79 "https://46.example/",
80};
82#define MAX_PARALLEL 10 /* number of simultaneous transfers */
83#define NUM_URLS (sizeof(urls) / sizeof(char *))
85static size_t write_cb(char *data, size_t n, size_t l, void *userp)
86{
87 /* take care of the data here, ignored in this example */
88 (void)data;
89 (void)userp;
90 return n * l;
91}
93static void add_transfer(CURLM *multi, unsigned int i, int *left)
94{
95 CURL *curl = curl_easy_init();
96 if(curl) {
97 curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_cb);
98 curl_easy_setopt(curl, CURLOPT_URL, urls[i]);
99 curl_easy_setopt(curl, CURLOPT_PRIVATE, urls[i]);
100 curl_multi_add_handle(multi, curl);
101 }
102 (*left)++;
103}
105int main(void)
106{
107 CURLM *multi;
109 CURLcode result = curl_global_init(CURL_GLOBAL_ALL);
110 if(result != CURLE_OK)
111 return (int)result;
113 multi = curl_multi_init();
114 if(multi) {
115 CURLMsg *msg;
116 unsigned int transfers = 0;
117 int msgs_left = -1;
118 int left = 0;
120 /* Limit the amount of simultaneous connections curl should allow: */
121 curl_multi_setopt(multi, CURLMOPT_MAXCONNECTS, (long)MAX_PARALLEL);
123 for(transfers = 0; transfers < MAX_PARALLEL && transfers < NUM_URLS;
124 transfers++)
125 add_transfer(multi, transfers, &left);
127 do {
128 int still_alive = 1;
129 curl_multi_perform(multi, &still_alive);
131 /* !checksrc! disable EQUALSNULL 1 */
132 while((msg = curl_multi_info_read(multi, &msgs_left)) != NULL) {
133 if(msg->msg == CURLMSG_DONE) {
134 const char *url;
135 CURL *curl = msg->easy_handle;
136 curl_easy_getinfo(curl, CURLINFO_PRIVATE, &url);
137 fprintf(stderr, "R: %d - %s <%s>\n", (int)msg->data.result,
138 curl_easy_strerror(msg->data.result), url);
139 curl_multi_remove_handle(multi, curl);
140 curl_easy_cleanup(curl);
141 left--;
142 }
143 else {
144 fprintf(stderr, "E: CURLMsg (%d)\n", (int)msg->msg);
145 }
146 if(transfers < NUM_URLS)
147 add_transfer(multi, transfers++, &left);
148 }
149 if(left)
150 curl_multi_wait(multi, NULL, 0, 1000, NULL);
152 } while(left);
154 curl_multi_cleanup(multi);
155 }
156 curl_global_cleanup();
158 return EXIT_SUCCESS;
159}
Diagnostics4 git calls · 28 ms
CallStatusSizeTime028 ms
discover200152 B2 ms
git.upload-pack discover http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch 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 · hit2 ms
git.upload-pack ls-refs http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=ls-refs git.upstream.dur_ms=2 git.response.bytes=149 git.response.cache=HIT git.response.duration_ms=2 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=23 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=86Open pack map
fetch2001.7 KiB · hit23 ms
git.upload-pack fetch http.response.status_code=200 git.response.bytes=1702 git.response.cache=HIT git.response.duration_ms=23 git.fetch.wants=34572e438b3e652261be37e4e00866bf024b6494 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=1702 git.pkt.payload.max=1681 git.sideband.band1.bytes=1680 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
- a5e309c9cd42ee28
- Request
- 385b9712…
- Protocol
- v2 · sha1
- Agent
- gitty/1.0
- Filter
- advertised
- Fetch
- shallow filter sideband-all
- Capabilities
- agent ls-refs fetch object-format