Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Swifty microservices in production
Search
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
Marcin Kliks
September 18, 2018
Technology
57
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Swifty microservices in production
Marcin Kliks
September 18, 2018
More Decks by Marcin Kliks
See All by Marcin Kliks
Droga do lepszego oprogramowania
vi4m
0
1.3k
Other Decks in Technology
See All in Technology
スプシの手作業からの解脱 ~更新はClaude Codeに、見せ方と使い方はGASアプリに任せる~
kentarofujii
0
150
LambdaWebFunctionsを試してみた / exploring-lambda-web-functions
koukihosaka
1
340
Tofu-Controller lightning talk @ Containerday 2026
gionn
0
110
大型犬好きによるPugの紹介
yamanoku
1
160
古い指輪から広がった JAVA コミュニティ とのつながり
yamad
0
110
10年後、Engineering 行為を剥奪されるとして、わたしたちは、どう、何を創ればいいだろうか。 / If Engineering Is Taken Away in 10 Years, How and What Should We Create?
bitkey
PRO
1
190
AI駆動で「他アプリの音を加工できる」アプリを作った
satomasahiro2005
0
150
実践!Cloud Run ハンズオン!! / Cloud Run handson
y0hgi
2
280
Railsで挑む大量データ永続化 〜600億件を永続化するための設計とボトルネックとの戦い〜
occhi
1
580
ソフトウェア ファクトリー - 再現性のあるソフトウェアの工場づくり / Software factory
iktakahiro
6
4.9k
コンテナ運用におけるネットワーク・コンテナコストの削減方法/How to Reduce Network and Container Costs in Container Operations
masakiokuda
1
210
WasmをRustにする
sansantech
PRO
0
250
Featured
See All Featured
Writing Fast Ruby
sferik
630
63k
We Analyzed 250 Million AI Search Results: Here's What I Found
joshbly
2
2k
RailsConf 2023
tenderlove
30
1.6k
[RailsConf 2023] Rails as a piece of cake
palkan
59
7.1k
The Curious Case for Waylosing
cassininazir
1
570
XXLCSS - How to scale CSS and keep your sanity
sugarenia
250
1.3M
Speed Design
sergeychernyshev
33
2.2k
Documentation Writing (for coders)
carmenintech
77
5.6k
A Guide to Academic Writing Using Generative AI - A Workshop
ks91
PRO
1
520
Odyssey Design
rkendrick25
PRO
2
870
The Impact of AI in SEO - AI Overviews June 2024 Edition
aleyda
6
1.2k
Amusing Abliteration
ianozsvald
1
350
Transcript
Swifty microservices in production Marcin Kliks Twitter: vi4m http://www.marcinkliks.pl
About • Marcin Kliks • Devops Teams Lead @ Allegro
• Ralph CMDB http://github.com/allegro/ ralph • Loves clean & performant code
None
http://www.allegro.pl
Backend stack Website (business logic) PaaS • 500+ microservices 2
Data Centers
The story of SSS
None
None
110 KB
3s Time budget Many reasons, images was one of them
Smaller images • WebP? • PNG and JPEG - most
compatible ones • Performant solution for thousands of images
None
Let’s shrink it!
Let’s shrink it! 30-40%
Mozjpeg 30%
Recompression is easy, right?
None
Image Compression • Allocate memory • Decompress • Recompress (quantization)
• Free memory 40 x RAM 4 MB image -> 160 MB RAM
Lots of images
Used Allocated Offer pool Mesos cluster
Used Allocated … Offer pool Mesos cluster
C library integration • How easy is it to integrate
and to compile? • How can you debug it? • What’s the performance / latency cost? • How do you release it? • Types conversion?
C library integration Single compiler Debugging Perf. Penalty Types briding
Golang ✅ (CGo) No 5x ❌ Java ❌ No 10 - 25x ❌ Python ❌ No Significant ❌ Swift ✅ Yes, Xcode Zero, native calls ✅
C library integration Single compiler Debugging Perf. Penalty Types briding
Golang ✅ (CGo) No 5x ❌ Java ❌ No 10 - 25x ❌ Python ❌ No Significant ❌ Swift ✅ Yes, Xcode Zero, native calls ✅
Swift c interop
Swift c interop String -> const char * Implicit type
conversion
from: raywenderlich.com
Performance • 3x lower memory usage than Java • Value
types! • No Garbage collector! • Predictive performance
How?
None
Swift
Swift Clang / LLVM
Swift Clang / LLVM
New language, new world Research project
Used components • Swift 4.1 • SPM • Vapor 2
(porting to 3) • GCD • HTTPS / TCP Client
Preparations • Choosing Server Side Swift framework • Prepare runtime
environment on Mesos • In-house Docker images for Swift • Plug into ecosystem • CI • One click deployment • Security checks • Compliance checks • Autodiscovery, logs, metrics … • Implement Microservice Contract
Microservice contract 1
Implementing microservice with Swift /status/ping addMicroserviceContractEndpoints(route)
Implementing microservice with Swift Configuration Metrics Logs
Implementing microservice with Swift Configuration Metrics Logs /status/ping
Implementing microservice with Swift Vault Graphite + Grafana Logstash +
Kibana /status/ping
Implementing microservice with Swift getConfigurationVariable(„DB_PASS”) Vault Graphite + Grafana Logstash
+ Kibana /status/ping
Vault configuration-file-test.yml database-name: [name]
Implementing microservice with Swift Vault Graphite + Grafana Logstash +
Kibana logger.info("Startup") /status/ping
Kibana logs
Implementing microservice with Swift Configuration Service pushMetrics(metricName:value) Graphite + Grafana
Logstash + Kibana /status/ping
Grafana
Implementing microservice with Swift • Helper library („swidamio”) • Configuration
Service Client • Graphite client • Logging client • Microservice Contract
Integrating C libraries 2
System or vendoring? • Linking to system libraries (installed with
homebrew, apt) • Faster compiles • Package manager responsible for updates • Sources included(„vendored”) within the app • Customizable • Longer compiles
System or vendoring? • `brew install mozjpeg`
None
None
None
None
None
None
None
Did we use pkg-config ?
pkg-config
pkg-config
None
None
None
None
custom-settings.xcconfig
None
Debugging both C + Swift code in XCode
Challenges
Segmentation fault
Challenges • Catching fatal errors in production / Sentry •
All functions throwable • Memory profiling in production • C-based profilers?
Deploy 3
0-dependencies deploy 1. Compilation on Docker 2. package.zip with all
libs 3. Unzip & run native on mesos
Demo
None
Results R
170 KB 90 KB
Swift minimal 25 MB of RAM Vapor 2.
250 MB of RAM Java, springboot
Swift - during compression of images Limit ~ 49 MB
of RAM
Startup time 0,2 sec ~ Servless like ~
None
Does it scale? Java 10 instances Swift 100
instances
2 * 100 instances in 40 seconds - including health
checks - nothing preinstalled on clusters
What’s next? • We just got started (PNG, one Showcase
Area) • Next step: compress more areas with PNG + JPG
Quanta Quanta - Open Source in November! http://allegro.tech
Good parts • FAST, predictive performance, and fast to scale
• Amazing c-libraries integration • Powerful language with safe code constructs
Missing parts… • Framework agnostic libraries like Logging, Metrics •
Boundles • Stacktraces for fatal C / Unwrap crashes • Memory profiling on Linux • Better tooling
What is Swift good for?
The best for • Performance-oriented microservices • Safer C libraries
wrappers • ML / CPython integration (Dynamic Callable) • …
Thank you Marcin Kliks
[email protected]
@vi4m Q & A