TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

How Discord Resizes 150M Images Every Day with Go and C++

303 pointsby b1naryth1efover 7 years ago

14 comments

Xeoncrossover 7 years ago
Why don&#x27;t more companies resize images client-side first using &lt;canvas&gt; and then save the server some work by only asking it to verify the result by<p>- resizing to the same size<p>- removing metadata<p>This results in much faster transfer (10x less bandwidth used often for mobile uploads) and reduces server load by &quot;farming&quot; out the work to the clients.<p><a href="https:&#x2F;&#x2F;developer.mozilla.org&#x2F;en-US&#x2F;docs&#x2F;Web&#x2F;API&#x2F;CanvasRenderingContext2D&#x2F;drawImage" rel="nofollow">https:&#x2F;&#x2F;developer.mozilla.org&#x2F;en-US&#x2F;docs&#x2F;Web&#x2F;API&#x2F;CanvasRende...</a><p># Edit: On Keeping Full Resolution Images<p>Some people mention having original highest-resolution images are important. I don&#x27;t think that is true for most applications.<p>Most apps don&#x27;t need hi-resolution history as much as current, live engagement so older photos being smaller isn&#x27;t a big deal. As technology moves on you simply start allowing higher-res uploads. Youtube, facebook, and others have done this fine as the older stuff is replaced with the new&#x2F;current&#x2F;now() content.<p>In fact, even our highest resolution images are still low-quality for the future. Pick a good max size for your site (4k?) and resize everything down to that. In a year, bump it up to 6k, then 10k, etc...<p>Keeping costs low has it&#x27;s benefits, especially for us startups. Now if you have massive collateral, then knock yourself out.
评论 #15697220 未加载
评论 #15697679 未加载
评论 #15697257 未加载
评论 #15697274 未加载
评论 #15699491 未加载
评论 #15698134 未加载
评论 #15697260 未加载
评论 #15699459 未加载
评论 #15697486 未加载
评论 #15697201 未加载
评论 #15697243 未加载
评论 #15698274 未加载
评论 #15697287 未加载
评论 #15701240 未加载
评论 #15698087 未加载
评论 #15697356 未加载
sgk284over 7 years ago
There is already an (unofficial Google) image proxy written in Go that is quite fast, does caching (local or backed by S3&#x2F;GCS), and does other nice things like smart cropping: <a href="https:&#x2F;&#x2F;github.com&#x2F;willnorris&#x2F;imageproxy" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;willnorris&#x2F;imageproxy</a><p>Seemed like a lot of unnecessary work for them to reimplement a service from scratch without gaining any major perf benefits over their existing one and without leaning on an existing well-known and well-built foundation.
评论 #15697823 未加载
评论 #15697856 未加载
评论 #15697413 未加载
gourouover 7 years ago
Link to the resulting open-source project:<p><a href="https:&#x2F;&#x2F;github.com&#x2F;discordapp&#x2F;lilliput" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;discordapp&#x2F;lilliput</a>
caltropsover 7 years ago
I’d be very worried about a security issue with the unsafe C++ code.<p>You really have to run this kind of complex parsing in a disposable containerized environment to do it safely. Or do everything carefully and in a memory safe language.
评论 #15697219 未加载
评论 #15698951 未加载
评论 #15701458 未加载
devwastakenover 7 years ago
How is the security? Any sort of image processing is a potential exploitation point. I see it says it uses the &#x27;mature&#x27; libjpeg-turbo and libpng libraries,along with giflib for .gifs, but even with full trust of those, the C code, patches, and changes ontop could be more exploitation points. You can look through Imagemagick alone to see all the fun things possible when seemingly basic processing turns into exploits. <a href="https:&#x2F;&#x2F;www.cvedetails.com&#x2F;vulnerability-list&#x2F;vendor_id-1749&#x2F;Imagemagick.html" rel="nofollow">https:&#x2F;&#x2F;www.cvedetails.com&#x2F;vulnerability-list&#x2F;vendor_id-1749...</a>
评论 #15697501 未加载
评论 #15697315 未加载
linkmotifover 7 years ago
&gt; Today, Media Proxy operates with a median per-image resize of 25ms and a median total response latency of 85ms. It resizes more than 150 million images every day. Media Proxy runs on an autoscaled GCE group of n1-standard-16 host type, peaking at 12 instances on a typical day.<p>Awesome! &lt;3
throwthisawaytover 7 years ago
Did it seem to anyone else that sticking to Python would have been way easier? It didn’t seem like any of the performance gains were through Golang.
评论 #15697179 未加载
评论 #15697081 未加载
评论 #15697276 未加载
评论 #15697196 未加载
评论 #15697186 未加载
评论 #15697165 未加载
JepZover 7 years ago
Anybody knows how well libvips <a href="https:&#x2F;&#x2F;github.com&#x2F;DAddYE&#x2F;vips" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;DAddYE&#x2F;vips</a> compares to liliput performance wise?
评论 #15697214 未加载
manigandhamover 7 years ago
Nice, but why? <a href="https:&#x2F;&#x2F;cloudinary.com" rel="nofollow">https:&#x2F;&#x2F;cloudinary.com</a>, <a href="https:&#x2F;&#x2F;www.imgix.com" rel="nofollow">https:&#x2F;&#x2F;www.imgix.com</a>, or <a href="https:&#x2F;&#x2F;www.filestack.com" rel="nofollow">https:&#x2F;&#x2F;www.filestack.com</a> already exist and are well worth it for 99% of apps. Even at scale, it really doesn&#x27;t cost that much to have someone else do it. You can use a thin proxy through your existing CDN if you want to save on their bandwidth fees.<p>Also <a href="http:&#x2F;&#x2F;thumbor.org" rel="nofollow">http:&#x2F;&#x2F;thumbor.org</a> and <a href="https:&#x2F;&#x2F;imageresizing.net" rel="nofollow">https:&#x2F;&#x2F;imageresizing.net</a> if you want a library to host yourself which are already very fast and well tested. Put them in a docker container on a kubernetes cluster and it&#x27;s all done in an hour.
评论 #15698091 未加载
评论 #15698593 未加载
ymseover 7 years ago
This post reminded me of a very old article from Yahoo&#x2F;Tumblr explaining how they were (ab)using Ceph to generate thumbnails on the fly as pictures were uploaded using the Ceph OSD plugin interface.<p>Unfortunately the post seems to have disappeared from the internet (it was probably around 6 years ago), so here are some other teasers:<p><a href="https:&#x2F;&#x2F;yahooeng.tumblr.com&#x2F;post&#x2F;116391291701&#x2F;yahoo-cloud-object-store-object-storage-at" rel="nofollow">https:&#x2F;&#x2F;yahooeng.tumblr.com&#x2F;post&#x2F;116391291701&#x2F;yahoo-cloud-ob...</a><p><a href="https:&#x2F;&#x2F;ceph.com&#x2F;geen-categorie&#x2F;dynamic-object-interfaces-with-lua&#x2F;" rel="nofollow">https:&#x2F;&#x2F;ceph.com&#x2F;geen-categorie&#x2F;dynamic-object-interfaces-wi...</a><p>Disclaimer: not affiliated with Ceph apart from being a happy sysadmin.
评论 #15700817 未加载
kylehotchkissover 7 years ago
I wish Cloudfront supported resize parameters so we wouldn&#x27;t have to keep buildings these or paying a lot for Imgix.
评论 #15698771 未加载
评论 #15697819 未加载
Const-meover 7 years ago
I wonder why people implement such things on CPU?<p>PCI express is ~100 gbit&#x2F;sec, much faster than any network interface. Internally, a GPU can resize these images by an order of magnitude faster than that, see the fillrate columns in the GPU spec.
评论 #15699586 未加载
评论 #15699432 未加载
tuananhover 7 years ago
is there any open source project img proxy that can do this?<p>eg: instead of this<p><a href="http:&#x2F;&#x2F;localhost:8080&#x2F;https:&#x2F;&#x2F;octodex.github.com&#x2F;images&#x2F;codercat.jpg" rel="nofollow">http:&#x2F;&#x2F;localhost:8080&#x2F;https:&#x2F;&#x2F;octodex.github.com&#x2F;images&#x2F;code...</a><p>we can create alias like octo and url will become this<p><a href="http:&#x2F;&#x2F;localhost:8080&#x2F;octo&#x2F;images&#x2F;codercat.jpg" rel="nofollow">http:&#x2F;&#x2F;localhost:8080&#x2F;octo&#x2F;images&#x2F;codercat.jpg</a>
0xbearover 7 years ago
That’s 1700 images per second. Doable on one (beefy) box. 3 to account for the diurnal cycle. Am I supposed to be impressed?
评论 #15700978 未加载
评论 #15700685 未加载