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#include "first.h"
26#include "curl_threads.h"
28#define THREAD_SIZE 16
29#define PER_THREAD_SIZE 8
31struct Ctx {
32 const char *URL;
33 CURLSH *share;
34 CURLcode result;
35 size_t thread_id;
36 struct curl_slist *contents;
37};
39static size_t write_memory_callback(char *contents, size_t size,
40 size_t nmemb, void *userp)
41{
42 /* append the data to contents */
43 size_t realsize = size * nmemb;
44 struct Ctx *mem = (struct Ctx *)userp;
45 char *data = curlx_malloc(realsize + 1);
46 struct curl_slist *item_append = NULL;
47 if(!data) {
48 curl_mprintf("not enough memory (malloc returned NULL)\n");
49 return 0;
50 }
51 memcpy(data, contents, realsize);
52 data[realsize] = '\0';
53 item_append = curl_slist_append(mem->contents, data);
54 curlx_free(data);
55 if(item_append) {
56 mem->contents = item_append;
57 }
58 else {
59 curl_mprintf("not enough memory (curl_slist_append returned NULL)\n");
60 return 0;
61 }
62 return realsize;
63}
65#ifdef USE_THREADS
66static CURL_THREAD_RETURN_T CURL_STDCALL test_thread(void *ptr)
67#else
68static unsigned int test_thread(void *ptr)
69#endif
70{
71 struct Ctx *ctx = (struct Ctx *)ptr;
72 CURLcode result = CURLE_OK;
74 int i;
76 /* Loop the transfer and cleanup the handle properly every lap. This
77 still reuses SSL session since the pool is in the shared object. */
78 for(i = 0; i < PER_THREAD_SIZE; i++) {
79 CURL *curl = curl_easy_init();
80 if(curl) {
81 curl_easy_setopt(curl, CURLOPT_URL, ctx->URL);
83 /* use the share object */
84 curl_easy_setopt(curl, CURLOPT_SHARE, ctx->share);
85 curl_easy_setopt(curl, CURLOPT_CAINFO, libtest_arg2);
87 curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_memory_callback);
88 curl_easy_setopt(curl, CURLOPT_WRITEDATA, ptr);
89 curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
91 /* Perform the request, result gets the return code */
92 result = curl_easy_perform(curl);
94 /* always cleanup */
95 curl_easy_cleanup(curl);
96 /* Check for errors */
97 if(result != CURLE_OK) {
98 curl_mfprintf(stderr, "curl_easy_perform() failed: %s\n",
99 curl_easy_strerror(result));
100 goto test_cleanup;
101 }
102 }
103 }
105test_cleanup:
106 ctx->result = result;
107 return 0;
108}
110#ifdef USE_THREADS
112static void t3207_test_lock(CURL *curl, curl_lock_data data,
113 curl_lock_access laccess, void *useptr)
114{
115 curl_mutex_t *mutexes = (curl_mutex_t *)useptr;
116 (void)curl;
117 (void)laccess;
118 Curl_mutex_acquire(&mutexes[data]);
119}
121static void t3207_test_unlock(CURL *curl, curl_lock_data data, void *useptr)
122{
123 curl_mutex_t *mutexes = (curl_mutex_t *)useptr;
124 (void)curl;
125 Curl_mutex_release(&mutexes[data]);
126}
128static void execute(CURLSH *share, struct Ctx *ctx)
129{
130 size_t i;
131 curl_mutex_t mutexes[CURL_LOCK_DATA_LAST - 1];
132 curl_thread_t thread[THREAD_SIZE];
133 for(i = 0; i < CURL_ARRAYSIZE(mutexes); i++) {
134 Curl_mutex_init(&mutexes[i]);
135 }
136 curl_share_setopt(share, CURLSHOPT_LOCKFUNC, t3207_test_lock);
137 curl_share_setopt(share, CURLSHOPT_UNLOCKFUNC, t3207_test_unlock);
138 curl_share_setopt(share, CURLSHOPT_USERDATA, (void *)mutexes);
139 curl_share_setopt(share, CURLSHOPT_SHARE, CURL_LOCK_DATA_SSL_SESSION);
141 for(i = 0; i < CURL_ARRAYSIZE(thread); i++) {
142 thread[i] = Curl_thread_create(test_thread, (void *)&ctx[i]);
143 }
144 for(i = 0; i < CURL_ARRAYSIZE(thread); i++) {
145 if(thread[i]) {
146 Curl_thread_join(&thread[i]);
147 Curl_thread_destroy(&thread[i]);
148 }
149 }
150 curl_share_setopt(share, CURLSHOPT_LOCKFUNC, NULL);
151 curl_share_setopt(share, CURLSHOPT_UNLOCKFUNC, NULL);
152 for(i = 0; i < CURL_ARRAYSIZE(mutexes); i++) {
153 Curl_mutex_destroy(&mutexes[i]);
154 }
155}
157#else /* without pthread, run serially */
159static void execute(CURLSH *share, struct Ctx *ctx)
160{
161 size_t i;
162 (void)share;
163 for(i = 0; i < THREAD_SIZE; i++) {
164 test_thread((void *)&ctx[i]);
165 }
166}
168#endif
170static CURLcode test_lib3207(const char *URL)
171{
172 CURLcode result = CURLE_OK;
173 size_t i;
174 CURLSH *share;
175 struct Ctx ctx[THREAD_SIZE];
177 curl_global_init(CURL_GLOBAL_ALL);
179 share = curl_share_init();
180 if(!share) {
181 curl_mfprintf(stderr, "curl_share_init() failed\n");
182 goto test_cleanup;
183 }
185 for(i = 0; i < CURL_ARRAYSIZE(ctx); i++) {
186 ctx[i].share = share;
187 ctx[i].URL = URL;
188 ctx[i].thread_id = i;
189 ctx[i].result = CURLE_OK;
190 ctx[i].contents = NULL;
191 }
193 execute(share, ctx);
195 for(i = 0; i < CURL_ARRAYSIZE(ctx); i++) {
196 if(ctx[i].result) {
197 result = ctx[i].result;
198 }
199 else {
200 const struct curl_slist *item = ctx[i].contents;
201 while(item) {
202 curl_mprintf("%s", item->data);
203 item = item->next;
204 }
205 }
206 curl_slist_free_all(ctx[i].contents);
207 }
209test_cleanup:
210 if(share)
211 curl_share_cleanup(share);
212 curl_global_cleanup();
213 return result;
214}
Diagnostics4 git calls · 113 ms
CallStatusSizeTime0113 ms
discover200152 B3 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 · 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 · hit2 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=108 git.response.bytes=293470 git.response.cache=HIT git.response.duration_ms=2 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
fetch2002.1 KiB108 ms
git.upload-pack fetch http.response.status_code=200 git.response.bytes=2157 git.response.cache=MISS git.response.duration_ms=108 git.fetch.wants=f28085c8652df96ea0e01ca2a5d208a40ea3a96c 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=2157 git.pkt.payload.max=2136 git.sideband.band1.bytes=2135 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
- a5e31defad5c8682
- Request
- cd3e68bc…
- Protocol
- v2 · sha1
- Agent
- gitty/1.0
- Filter
- advertised
- Fetch
- shallow filter sideband-all
- Capabilities
- agent ls-refs fetch object-format