We began by benchmarking existing image resizing packages for Go and quickly discovered something disheartening. In addition to serving requests faster, the new service would also get new features, including the ability to get the first frame from. Thankfully, Image Proxy was relatively simple, and comparing results between it and the replacement service would be straightforward. It’s not an easy decision to rewrite a service that’s already working. We likely could have addressed this behavior in Image Proxy, but we had been experimenting with using more Go, and it seemed like a good place to try Go out. Image proxying requests saw a wide variance of response times, with some taking multiple seconds to complete. The biggest problem was the Image Proxy did not have an even workload distribution, which hampered its throughput. Still, as Discord grew, the Image Proxy started to show signs of strain. This combination of cache and proxy was enough to scale our image proxy up well into millions of users. The cache performs request coalescing in order to minimize the number of resize transformations required. A HAProxy layer routes requests based on a URL hash to the Nginx caching layer. On top of this, we setup a caching layer that would try to keep resized images around in memory and respond directly from cache when it could. The Image Proxy would receive a HTTP request containing a URL to fetch, resize, and finally respond with the image. Pillow-simd is wonderfully fast and uses x86 SSE instructions to accelerate resizing where it can. It fetched images from remote URLs and then used the pillow-simd package to do the heavy lifting of image resizing. To handle this job, we created a Python service creatively named Image Proxy. To circumvent these problems, Discord needs an intermediary service to fetch images on behalf of users and then resize them to reduce bandwidth usage. Linking directly to images would leak users’ IP addresses to image hosts, and large images use up lots of bandwidth. While we wish it was as simple as sending them out across the tubes to your friends, delivering these images creates some pretty large technical problems. Despite being a voice and text chat app, Discord sees over a hundred million images passing through its tubes every day.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |