Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Go for speed

9d198f37cdf56e90b09b5efd39b36d83?s=47 Nick Bruun
September 18, 2014

Go for speed

A look at a use case for Go at Iconfinder, which shaved ~40 ms off asset load times.

9d198f37cdf56e90b09b5efd39b36d83?s=128

Nick Bruun

September 18, 2014
Tweet

Transcript

  1. Go for speed

  2. Nick Bruun github.com/nickbruun @nickbruun bruun.co CTO @ Iconfinder Fairly carnivorous

  3. None
  4. None
  5. None
  6. Trouble in icon paradise

  7. None
  8. None
  9. None
  10. None
  11. 41 ms average response time from Django application during peak

    hours
  12. ~2,000 ms wasted per search

  13. Perceivably slower

  14. The internals

  15. None
  16. Icon ID Icon version ID Raster size https://www.iconfinder.com/icons/298255/677266/128/raster https://cdn0.iconfinder.com/data/icons/seo-smart-pack/128/ grey_new_seo2-43-128.png

    Public raster URL Protected raster URL
  17. None
  18. Constant

  19. Signing requests

  20. https://www.iconfinder.com/icons/298255/677266/128/raster?token=…

  21. None
  22. we know if the user has access right now When

    returning the link,
  23. we know if the user has access right now When

    returning the link,
  24. We’re okay with “right now” being an approximation

  25. Time limited token

  26. <token secret> = "<expiration timestamp>-<session ID>-<nonce>-<URL>"

  27. <token secret> = "<expiration timestamp>-<session ID>-<nonce>-<URL>" <signature> = hmac_sha1(<token secret>,

    <shared secret>)
  28. <token secret> = "<expiration timestamp>-<session ID>-<nonce>-<URL>" <signature> = hmac_sha1(<token secret>,

    <shared secret>) <token> = "<expiration timestamp>-<nonce>-base64(<signature>)"
  29. But, who checks the token?

  30. Enter Go The World’s least Google-able language… from Google

  31. None
  32. Why Go?

  33. Networked service

  34. Highly concurrent ~3,000 requests/second from 100 connections/core

  35. Low memory footprint 14.09 MiB after 21 days

  36. Low CPU usage

  37. Static binary Cross-compilation = deployment heaven

  38. Less decisions to make

  39. Caveats

  40. Structured logging

  41. DIY

  42. Mature runtime != Mature language

  43. Conciseness 608 lines of code

  44. The end result

  45. 1.2 ms average response time at peak hours

  46. 0.1 % CPU usage at peak hours

  47. Go is awesome

  48. Go is awesome for simple services

  49. Go is a trade-off

  50. Go is a trade-off – choose wisely

  51. return