hey guys does anyone here use a tunnel
hey guys, does anyone here use a tunnel to your server for a Web API ?
i did it and it makes it 3 times slower
what should i do ?
36 Replies
You're using A CF Tunnel? Your setup is a simple REST API, with small responses, or?
You're talking about 3.5s through CF Proxy vs 15s through Tunnel, or unproxied?
opps, forgot to mention in reply @Xabaras
Hey @Chaika i use the tunnels in the zero trust app
i have a dotnet 7 web api, and i serve a lot of images
for ex i had 180 pics and the request was 15 sec
it takes 3.5 seconds through a direct connection to the server which is in my home network, from where im accessing it
3.5-5 seconds max depending on image count
direct connection to the server in your LAN isn't really a good comparison. You have 180 pictures you download at once, at the same time, or in a zip? If it's a huge file, you're generally going to have much faster speeds on LAN then going over the internet
thats true yes
i have like 180pics that i get from the servers SSD
is there a better way to do this ? If you know any alternatives
well, I'm still a bit confused to what exactly you are doing. You have like a gallery website with a ton of pictures? you're downloading a zip with a ton of pictures? What's the exact use? There's a big difference between one big download and 180 tiny downloads
i have an angular app that targets the web api, which is on my IIS server, that i use Cloudflare tunnel to access
i have a domain on cloudflare which tunnels to my ip address
i get the images as base64 format
so you fetch each image, one at a time? If you look at the network tools using the tunnel vs direct locally, each image is just a bit slower over the tunnel, but collectively much slower?
i get a list of entities where each has many images
for ex 10 entites each having 10-20 images
so you do like 8 of those API calls, and get all of the images? How large is the response? Is that where you got the 3s to 15s numbers from?
i do 1 API call, getting a list of entities each having multiple pictures
yes thats is where i get the difference
its max 5sec Lan and 15-20 on the CF tunnel
ahhh ok, it's a single API call that is just much slower
yes
What's the response size?
lemme see
i think 100mb
if you ctrl+shift+i, and go to network tab, you can see the exact response size
just a moment
rn its 58.6mb with 118 pictures
Sure, the next thing I would check is your download/upload speed: https://speed.cloudflare.com/
Even if you have decent download, a lot of ISPs give very asymmetric speeds and you might have slow upload. If you had an upload speed of about 20 Mbps, it would take you about 25 seconds to upload 60 MB file (https://downloadtimecalculator.com/Upload-Time-Calculator.html). The thing about the tunnel is that your internet has to both upload the file to Cloudflare, and also download it from it, at the same time.
okay
im checking it out rn
45.7
Mbps
download or upload?
could i use other server locations closer to me ?
those aren't bad, a bit of variance, but still, if you had an upload of ~30 MBPS of so, it would take you 15 seconds or so to download 60 MB
the speed test already selects the closest
okay cool
but are these speed tests going to be the same if i dont use a tunnel ?
beacuse i've seen some people say it makes their api 2,3x slower
Tunnel vs just CF Proxy?
or vs LAN?
not lan
i guess CF proxy
im not very good with networks
Tunnels aren't great a big files, but that file isn't too big imo. You could try with just the normal proxy, but you would have to port forward/etc.
If you could cache the images at all, or upload them to something online, like Cloudflare's R2 Storage, it would be way quicker. It seems at the moment you're just being bottlenecked by your WAN/Internet speeds
yeah the main idea was to have my server and store the images on an SSD, should i try the normal proxy ?
I mean it wouldn't hurt to try, might be a pain to configure though with port forwarding and such, depending on how familiar you are with it.
I wouldn't expect big increases though, you're kind of just capped by your internet speed
would that be the optimal way to do this ?
counting the internet speed out
I wouldn't say optimal, tunnels are really cool because they remove the need to port forward and are super secure. I know from other people talking about it before, like running Linux mirrors with tunnels, that they're just not great with huge gigabyte sized files. I think you're more on the reasonable edge of things, but I wouldn't count out any speed improvements
If you wanted to try to improve something, try not to base64 encode your images if you can. Base64 adds a 33% size overhead on things, if you could maybe locally compress them into an archive format like a zip. If you're trying to show them on a website, if you load them one at a time and use lazy loading (https://stackoverflow.com/a/57389607), you could benefit from Cloudflare's cache as well
i should check out the compression for sure
but i load them as a batch
i have patients and visits
and each visit has multiple pics i show in a mat-dialog
so idk about the lazy loading
but compressing absolutely
you're showing like 110 pictures on screen at the same time?
No, when i open the dialog for a certain visit
so it's like when they open the app or view a specific item, they load all the pictures associated?
well eitherway, I would strongly encourage you to just load them as normal images and not as some base64 batch or anything like that, maybe back in the day it was a good idea, now it's just not really: https://bunny.net/blog/why-optimizing-your-images-with-base64-is-almost-always-a-bad-idea/
Lazy load them, if they're immutable cache them both in Cloudflare (if public) or browser like crazy, get away from the base64 overhead, etc
Why "optimizing" your images with Base64 is almost always a bad idea
Why "optimizing" your images with Base64 is almost always a bad idea
We want to address why in this day and age, this is almost always a very bad idea to "optimize" your images by encoding them to Base64.
Yes
Okay thanks a lot man
I will certainly do this