SlideShare a Scribd company logo
Real-world Experiences
in
Scala
How I found happiness
by Amir Karimi | www.dev-frame.com
Aug 2015
Philosophy of Life
It's about the journey not the destination
If you want to be happy
Geeks Philosophy
It's about the tools not the work
If you want to be a happy developer
My Philosophy
I'm happy with Linux and Scala
for now
Bio
The Past
●
Fanatic C# Developer for 10 years
●
Lived in MS echo chamber
●
.NET CF, WinForms, WebForms, MVC, WF, WCF, WPF,
Silverlight, LINQ, EF, MS SQL, VS, etc.
●
Love Linux: in my dreams I was developing on my own Linux
machine!
Converting; Why?
●
Tired of MS echo chamber
●
Feel lonely
●
Love Linux and Open Source
●
To run a huge private server with less than 2GB of RAM
– Clean installation of Ubuntu server 14.04 takes less than 50MB of RAM
– Windows Server 2012 Essentials needs at least 2048MB?
●
To observe copyright and licensing (VS, Windows Server/Client, SQL Server,
etc.)
My Ideal Programming
Language
●
Open Source
●
Cross platform (Practically)
●
Ready to use with mature ecosystem (Practical)
●
Strongly-type / Type-safe
●
Lambdas / Closures => Functional (I was thinking about LINQ)
●
Object Oriented (Interfaces, Generics, ...)
●
Modern (Not Verbose: Type inference, Auto Getter/Setter, …)
Available ones
●
C# - Cross Platform (Practically)
●
Python / Ruby / JS - Strongly-type / Type-safe
●
Java - Modern (Not Verbose: Type inference, Auto Getter/Setter,
…) and didn't support lambdas at the time
●
Go - Ready to use with mature ecosystem | Object Oriented
(Interfaces, Generics, …)
●
Scala - What?
Scala Features
●
Type inference
●
Powerful Syntax
●
Functional
●
DSL
●
Immutable Structures
●
Case Classes
●
Pattern Matching
●
Implicits
●
Macros
●
Powerful Type System and
Standard Library
●
etc.
Demo
Scala Features
Extra Bonus
● Moore's law dying and the need of concurrent programming
– Facts
●
First 3GHz single core CPU at 2002
●
It's 13 years and there are still just 3GHz CPUs
●
But with more cores (your cellphone would have 4)
●
Thread blocking is very expensive
– Scala and other functional programming languages shine here
– Akka is another bonus
●
Somebody created a Redis clone on top of Akka (CurioDB)
● Big Data
– Spark is on top of Scala and Akka (100x faster than Hadoop)
My New Ecosystem
● Scala
– The only available language which meet my needs
● Play Framework
– Mature, Type-safe (even templates), High Velocity, Async, Iteratees,
Simple to Use
● MongoDB
– Open Source, Fast, Distributed, Schema Free, Not good for everything
● ReactiveMongo
– Blazingly Fast, Async, Iteratees
Demo
Play Framework
Demo
MongoDB
Deployment Requirement
●
Development Machine
– JDK
– Activator (Play)
– Git (to push the binaries to the
server)
– Bash
●
Production Server
– JRE (I don't use this server as build machine)
– Nginx (as front-end if you have more than one
web apps)
– Virtualmin
●
DNS
●
Main Server
●
Webmail
– MongoDB
– Git (as binary repository for publishing process)
Deployment Process
Development Machine Production Server
Source
Bin Bare Git Repo
“/var/webapps/[app]
service play-[app] restart
Show Me the Code
Deployment
Real-world Projects
Tehran International Book Fair
● Website
● Publisher Registration System
● Student Coupon Selling System
Real-world Projects
● Tehran International Book Fair (TIBF) Website
– Up to 40,000 unique visitors daily
– 2,287 publishers
– 361,788 books
● TIBF Publisher Registration System
– Registration process of TIBF
– About 24,000,000,000 IRR ≈ 700,000$ total transactions in three weeks
● TIBF Student Coupon Selling System
– With a quota system based on provinces
– More than 500 request/sec
– About 87,000,000,000 IRR ≈ 2,600,000$ total transactions in three weeks
Challenges
●
TIBF Website
– Large number of RPS on book search page
●
Users can find their favorite book location
●
TIBF Registration System
– Complicated process on top of NoSQL database
●
TIBF Student Coupon Selling System
– Large number of RPS
– Large number of financial transactions
– Integration with Bank
Summary:
●
High availability
●
Large number of RPS
●
Complicated processes on top of NoSQL
● One small server for all of them
– 6 cores
– 6 GB of RAM
– Non-SSD hard disk
Solutions – High Velocity
●
Play is a high velocity Framework by default
●
Using async/non-blocking data-access library: ReactiveMongo
●
Futures and Promises
●
Iteratees (for rendering huge data with minimum resource
usage: RAM or CPU)
●
Everything is perfect; even didn't need caching!
Solutions – NoSQL
●
Manage relationships asynchronously
– Get fair information → Get registration information → Get basic information → …
●
All non-block
– Repeat data
●
Fairs in which the exhibitor is registered
●
Registered exhibitors for each fair
– Search
●
Generate keywords on CUD, don't use RegEx
●
NoSQL is not suitable for a system with complex relationships
●
Reports are painful but amazingly fast
– Need a job to collect data into another collection
– For real-time reports, data should be collected on CUD events
Solutions - Integration
●
Scala is on top of JVM with a huge high quality libraries
– I needed Rijndael-256 which is not common and is not implemented in Java
standard libraries
●
Bouncycastle
●
Also used
– Play's WS as web service client
– Scalaxb to generate WSDL classes (they didn't support REST)
– Again everything is async
Libraries and Tools - 100%
Free●
OS
– Linux (server and development)
●
IDE and Tools
– Activator
– Scala IDE
– RoboMongo
– Git
●
DB
– MongoDB
●
Front-end Server
– Nginx
●
Framework Libraries
– Play Framework
– ReactiveMongo
– Macwire (compile-time DI)
– Silhouette (authentication)
– Scrimage (image resizing)
– Persianutils by Bahman Movaghar
– Bouncycastle
– Xcala; my own application library
– etc.
Well Done!
●
Common
– Full-stack development
– Full async architecture (top to
bottom)
– Very good RAM usage except for
exporting Excel files
●
TIBF Website
– Less than 100ms responses on
peak times
●
TIBF Registration System
– Most of the publishers were happy
– Most of the operators were happy
– I was agile to implement real-time
requests in minutes or hours
●
TIBF Coupon System
– Boom! Things didn't go well
– Although about 5,000 successful
purchases have been done in a couple of
hours...
Failure
●
After lunching the TIBF coupon website, all websites seemed down
●
but the system load was OK!
●
Incomplete payments started to show up
– Verified payments without having invoices marked as paid
– Double payments
●
Stress
– Loneliness
– Failure
Failure
I Failed :(((((
●
Bad feeling about Scala
●
Feels like someone is pouring ice water on my head
●
A weird kind of relief
●
Everything got quiet
Didn't Give Up
●
Took a break, got relaxed and focused
●
Checked the bandwidth
●
Checked the server disk speed
●
Checked the logs
– Nginx: Too many open files
●
Checked the connections
– netstat -na | grep :80 | wc -l
●
About 4,000 open connections!
●
Google
– Default OS limitation for open
files is 4,000
– There is a simple solution for
“Too many open files”
– It was a victory! I could have
reach to the OS limits on a
small server
Fix
●
Add “fs.file-max” to “/etc/sysctl.conf”
●
Set soft and hard limits in “/etc/security/limits.conf” for Nginx and the user
by which Play apps are running
●
Set “worker_rlimit_nofile” in “/usr/local/nginx/conf/nginx.conf”
●
The server begin responding but the RAM was still too low
– Exporting Excel files for operators eats the RAM
– The laptop I used for this presentation has
more RAM than the server did (6GB)
6GB
3M$
Final Relief
●
They gave me a giant server
– 120 Core
– 128 GB of RAM
●
I used at most lest than 1% of this server
resources!
●
Although again I increased the default
OS limitation on number of open files
●
And their network got a serious problem
Servers; Old / New
Bonus Demo
Iteratees in Action
Bonus Demo
Speed in Action
Thank you
Build amazing things with your lovely tools
Iran-SUG => Iranian Scala User Group
Amir Karimi <a.karimi.k@gmail.com>
@4m1rk
www.dev-frame.com

More Related Content

PPTX
Scaling High Traffic Web Applications
Achievers Tech
 
PDF
Scaling with Symfony - PHP UK
Ricard Clau
 
PDF
[Start] Playing
佑介 九岡
 
PDF
Design a scalable site: Problem and solutions
Chau Thanh
 
PDF
2013 - Igor Sysoev - NGINx: origen, evolución y futuro - PHP Conference Argen...
PHP Conference Argentina
 
PDF
Cluster Fudge: Recipes for WordPress in the Cloud (WordCamp Austin 2014 Speaker)
Grant Norwood
 
PPTX
Day 9 - PostgreSQL Application Architecture
Barry Jones
 
KEY
Tech4Africa - Tuning LAMP, and beyond LAMP
Jason Norwood-Young
 
Scaling High Traffic Web Applications
Achievers Tech
 
Scaling with Symfony - PHP UK
Ricard Clau
 
[Start] Playing
佑介 九岡
 
Design a scalable site: Problem and solutions
Chau Thanh
 
2013 - Igor Sysoev - NGINx: origen, evolución y futuro - PHP Conference Argen...
PHP Conference Argentina
 
Cluster Fudge: Recipes for WordPress in the Cloud (WordCamp Austin 2014 Speaker)
Grant Norwood
 
Day 9 - PostgreSQL Application Architecture
Barry Jones
 
Tech4Africa - Tuning LAMP, and beyond LAMP
Jason Norwood-Young
 

What's hot (20)

PDF
CFWheels - Pragmatic, Beautiful Code
indiver
 
PDF
IoT and developer chances
Chau Thanh
 
PDF
Big Data! Great! Now What? #SymfonyCon 2014
Ricard Clau
 
PDF
4Developers 2015: Scaling LAMP doesn't have to suck - Sebastian Grodzicki
PROIDEA
 
PDF
Redis Everywhere - Sunshine PHP
Ricard Clau
 
PPTX
Automating Your Daily Tasks with Scripting - RubyConf 2015 Taiwan
Adler Hsieh
 
PDF
A Gentle Introduction to Functions-as-a-Service
Valeri Karpov
 
PDF
High-performance high-availability Plone
Guido Stevens
 
PDF
About Caching
Weng Wei
 
PDF
Redis : Database, cache, pub/sub and more at Jelly button games
Redis Labs
 
KEY
Messaging, interoperability and log aggregation - a new framework
Tomas Doran
 
PDF
Modern software architectures - PHP UK Conference 2015
Ricard Clau
 
PDF
Beyond Apache: Faster Web Servers
webhostingguy
 
PDF
Enterprise messaging
ColdFusionConference
 
KEY
Ship It ! with Ruby/ Rails Ecosystem
Yi-Ting Cheng
 
PDF
Riak at Posterous
capotej
 
PDF
Cache hcm-topdev
Thanh Chau
 
PDF
Server Check.in case study - Drupal and Node.js
Jeff Geerling
 
KEY
SSJS, NoSQL, GAE and AppengineJS
Eugene Lazutkin
 
PDF
Social Connections 2015 CrossWorlds and Domino
Paul Withers
 
CFWheels - Pragmatic, Beautiful Code
indiver
 
IoT and developer chances
Chau Thanh
 
Big Data! Great! Now What? #SymfonyCon 2014
Ricard Clau
 
4Developers 2015: Scaling LAMP doesn't have to suck - Sebastian Grodzicki
PROIDEA
 
Redis Everywhere - Sunshine PHP
Ricard Clau
 
Automating Your Daily Tasks with Scripting - RubyConf 2015 Taiwan
Adler Hsieh
 
A Gentle Introduction to Functions-as-a-Service
Valeri Karpov
 
High-performance high-availability Plone
Guido Stevens
 
About Caching
Weng Wei
 
Redis : Database, cache, pub/sub and more at Jelly button games
Redis Labs
 
Messaging, interoperability and log aggregation - a new framework
Tomas Doran
 
Modern software architectures - PHP UK Conference 2015
Ricard Clau
 
Beyond Apache: Faster Web Servers
webhostingguy
 
Enterprise messaging
ColdFusionConference
 
Ship It ! with Ruby/ Rails Ecosystem
Yi-Ting Cheng
 
Riak at Posterous
capotej
 
Cache hcm-topdev
Thanh Chau
 
Server Check.in case study - Drupal and Node.js
Jeff Geerling
 
SSJS, NoSQL, GAE and AppengineJS
Eugene Lazutkin
 
Social Connections 2015 CrossWorlds and Domino
Paul Withers
 
Ad

Similar to Real-world Experiences in Scala (20)

PDF
Virtualizing Development
Adam Culp
 
PDF
kranonit S06E01 Игорь Цинько: High load
Krivoy Rog IT Community
 
PDF
Ansible deployment
Didiet A. Pambudiono
 
PDF
Proper Care and Feeding of a MySQL Database for Busy Linux Administrators
Dave Stokes
 
ODP
Drupal Performance and Scaling
Gerald Villorente
 
PDF
The Proper Care and Feeding of a MySQL Database for Busy Linux Admins -- SCaL...
Dave Stokes
 
PDF
Screaming Fast Wpmu
djcp
 
PDF
Linuxfest Northwest Proper Care and Feeding Of a MySQL for Busy Linux Admins
Dave Stokes
 
ODP
Deploying Perl apps on dotCloud
daoswald
 
PDF
Cloud arch patterns
Corey Huinker
 
PDF
Backend & Frontend architecture scalability & websockets
Anne Jan Brouwer
 
PDF
Netty training
Jackson dos Santos Olveira
 
PDF
Go with the Flow - A Guide to a WordPress Workflow
Ann Cascarano
 
PDF
DrupalCampLA 2014 - Drupal backend performance and scalability
cherryhillco
 
PDF
Netty training
Marcelo Serpa
 
PDF
[HKOSCON][20180616][Containerized High Availability Virtual Hosting Deploymen...
Wong Hoi Sing Edison
 
PDF
Beyond Puppet
Kris Buytaert
 
PDF
Go with the Flow - A Guide to a WordPress Workflow
Ann Cascarano
 
PDF
Openstack India May Meetup
Deepak Garg
 
PPTX
The Professional Programmer
Dave Cross
 
Virtualizing Development
Adam Culp
 
kranonit S06E01 Игорь Цинько: High load
Krivoy Rog IT Community
 
Ansible deployment
Didiet A. Pambudiono
 
Proper Care and Feeding of a MySQL Database for Busy Linux Administrators
Dave Stokes
 
Drupal Performance and Scaling
Gerald Villorente
 
The Proper Care and Feeding of a MySQL Database for Busy Linux Admins -- SCaL...
Dave Stokes
 
Screaming Fast Wpmu
djcp
 
Linuxfest Northwest Proper Care and Feeding Of a MySQL for Busy Linux Admins
Dave Stokes
 
Deploying Perl apps on dotCloud
daoswald
 
Cloud arch patterns
Corey Huinker
 
Backend & Frontend architecture scalability & websockets
Anne Jan Brouwer
 
Go with the Flow - A Guide to a WordPress Workflow
Ann Cascarano
 
DrupalCampLA 2014 - Drupal backend performance and scalability
cherryhillco
 
Netty training
Marcelo Serpa
 
[HKOSCON][20180616][Containerized High Availability Virtual Hosting Deploymen...
Wong Hoi Sing Edison
 
Beyond Puppet
Kris Buytaert
 
Go with the Flow - A Guide to a WordPress Workflow
Ann Cascarano
 
Openstack India May Meetup
Deepak Garg
 
The Professional Programmer
Dave Cross
 
Ad

Recently uploaded (20)

PPTX
Maximizing Revenue with Marketo Measure: A Deep Dive into Multi-Touch Attribu...
bbedford2
 
PDF
New Download MiniTool Partition Wizard Crack Latest Version 2025
imang66g
 
PPTX
classification of computer and basic part of digital computer
ravisinghrajpurohit3
 
PDF
MiniTool Power Data Recovery Crack New Pre Activated Version Latest 2025
imang66g
 
PDF
Using licensed Data Loss Prevention (DLP) as a strategic proactive data secur...
Q-Advise
 
DOCX
Can You Build Dashboards Using Open Source Visualization Tool.docx
Varsha Nayak
 
PPTX
TRAVEL APIs | WHITE LABEL TRAVEL API | TOP TRAVEL APIs
philipnathen82
 
PPTX
The-Dawn-of-AI-Reshaping-Our-World.pptxx
parthbhanushali307
 
PPTX
Presentation about variables and constant.pptx
safalsingh810
 
PDF
49785682629390197565_LRN3014_Migrating_the_Beast.pdf
Abilash868456
 
PPTX
Presentation about Database and Database Administrator
abhishekchauhan86963
 
PPTX
AI-Ready Handoff: Auto-Summaries & Draft Emails from MQL to Slack in One Flow
bbedford2
 
PDF
Adobe Illustrator Crack Full Download (Latest Version 2025) Pre-Activated
imang66g
 
PDF
Key Features to Look for in Arizona App Development Services
Net-Craft.com
 
PDF
Protecting the Digital World Cyber Securit
dnthakkar16
 
PDF
advancepresentationskillshdhdhhdhdhdhhfhf
jasmenrojas249
 
PPT
Activate_Methodology_Summary presentatio
annapureddyn
 
PDF
Exploring AI Agents in Process Industries
amoreira6
 
PDF
lesson-2-rules-of-netiquette.pdf.bshhsjdj
jasmenrojas249
 
PDF
Applitools Platform Pulse: What's New and What's Coming - July 2025
Applitools
 
Maximizing Revenue with Marketo Measure: A Deep Dive into Multi-Touch Attribu...
bbedford2
 
New Download MiniTool Partition Wizard Crack Latest Version 2025
imang66g
 
classification of computer and basic part of digital computer
ravisinghrajpurohit3
 
MiniTool Power Data Recovery Crack New Pre Activated Version Latest 2025
imang66g
 
Using licensed Data Loss Prevention (DLP) as a strategic proactive data secur...
Q-Advise
 
Can You Build Dashboards Using Open Source Visualization Tool.docx
Varsha Nayak
 
TRAVEL APIs | WHITE LABEL TRAVEL API | TOP TRAVEL APIs
philipnathen82
 
The-Dawn-of-AI-Reshaping-Our-World.pptxx
parthbhanushali307
 
Presentation about variables and constant.pptx
safalsingh810
 
49785682629390197565_LRN3014_Migrating_the_Beast.pdf
Abilash868456
 
Presentation about Database and Database Administrator
abhishekchauhan86963
 
AI-Ready Handoff: Auto-Summaries & Draft Emails from MQL to Slack in One Flow
bbedford2
 
Adobe Illustrator Crack Full Download (Latest Version 2025) Pre-Activated
imang66g
 
Key Features to Look for in Arizona App Development Services
Net-Craft.com
 
Protecting the Digital World Cyber Securit
dnthakkar16
 
advancepresentationskillshdhdhhdhdhdhhfhf
jasmenrojas249
 
Activate_Methodology_Summary presentatio
annapureddyn
 
Exploring AI Agents in Process Industries
amoreira6
 
lesson-2-rules-of-netiquette.pdf.bshhsjdj
jasmenrojas249
 
Applitools Platform Pulse: What's New and What's Coming - July 2025
Applitools
 

Real-world Experiences in Scala

  • 1. Real-world Experiences in Scala How I found happiness by Amir Karimi | www.dev-frame.com Aug 2015
  • 2. Philosophy of Life It's about the journey not the destination If you want to be happy
  • 3. Geeks Philosophy It's about the tools not the work If you want to be a happy developer
  • 4. My Philosophy I'm happy with Linux and Scala for now
  • 5. Bio
  • 6. The Past ● Fanatic C# Developer for 10 years ● Lived in MS echo chamber ● .NET CF, WinForms, WebForms, MVC, WF, WCF, WPF, Silverlight, LINQ, EF, MS SQL, VS, etc. ● Love Linux: in my dreams I was developing on my own Linux machine!
  • 7. Converting; Why? ● Tired of MS echo chamber ● Feel lonely ● Love Linux and Open Source ● To run a huge private server with less than 2GB of RAM – Clean installation of Ubuntu server 14.04 takes less than 50MB of RAM – Windows Server 2012 Essentials needs at least 2048MB? ● To observe copyright and licensing (VS, Windows Server/Client, SQL Server, etc.)
  • 8. My Ideal Programming Language ● Open Source ● Cross platform (Practically) ● Ready to use with mature ecosystem (Practical) ● Strongly-type / Type-safe ● Lambdas / Closures => Functional (I was thinking about LINQ) ● Object Oriented (Interfaces, Generics, ...) ● Modern (Not Verbose: Type inference, Auto Getter/Setter, …)
  • 9. Available ones ● C# - Cross Platform (Practically) ● Python / Ruby / JS - Strongly-type / Type-safe ● Java - Modern (Not Verbose: Type inference, Auto Getter/Setter, …) and didn't support lambdas at the time ● Go - Ready to use with mature ecosystem | Object Oriented (Interfaces, Generics, …) ● Scala - What?
  • 10. Scala Features ● Type inference ● Powerful Syntax ● Functional ● DSL ● Immutable Structures ● Case Classes ● Pattern Matching ● Implicits ● Macros ● Powerful Type System and Standard Library ● etc.
  • 12. Extra Bonus ● Moore's law dying and the need of concurrent programming – Facts ● First 3GHz single core CPU at 2002 ● It's 13 years and there are still just 3GHz CPUs ● But with more cores (your cellphone would have 4) ● Thread blocking is very expensive – Scala and other functional programming languages shine here – Akka is another bonus ● Somebody created a Redis clone on top of Akka (CurioDB) ● Big Data – Spark is on top of Scala and Akka (100x faster than Hadoop)
  • 13. My New Ecosystem ● Scala – The only available language which meet my needs ● Play Framework – Mature, Type-safe (even templates), High Velocity, Async, Iteratees, Simple to Use ● MongoDB – Open Source, Fast, Distributed, Schema Free, Not good for everything ● ReactiveMongo – Blazingly Fast, Async, Iteratees
  • 16. Deployment Requirement ● Development Machine – JDK – Activator (Play) – Git (to push the binaries to the server) – Bash ● Production Server – JRE (I don't use this server as build machine) – Nginx (as front-end if you have more than one web apps) – Virtualmin ● DNS ● Main Server ● Webmail – MongoDB – Git (as binary repository for publishing process)
  • 17. Deployment Process Development Machine Production Server Source Bin Bare Git Repo “/var/webapps/[app] service play-[app] restart
  • 18. Show Me the Code Deployment
  • 19. Real-world Projects Tehran International Book Fair ● Website ● Publisher Registration System ● Student Coupon Selling System
  • 20. Real-world Projects ● Tehran International Book Fair (TIBF) Website – Up to 40,000 unique visitors daily – 2,287 publishers – 361,788 books ● TIBF Publisher Registration System – Registration process of TIBF – About 24,000,000,000 IRR ≈ 700,000$ total transactions in three weeks ● TIBF Student Coupon Selling System – With a quota system based on provinces – More than 500 request/sec – About 87,000,000,000 IRR ≈ 2,600,000$ total transactions in three weeks
  • 21. Challenges ● TIBF Website – Large number of RPS on book search page ● Users can find their favorite book location ● TIBF Registration System – Complicated process on top of NoSQL database ● TIBF Student Coupon Selling System – Large number of RPS – Large number of financial transactions – Integration with Bank Summary: ● High availability ● Large number of RPS ● Complicated processes on top of NoSQL ● One small server for all of them – 6 cores – 6 GB of RAM – Non-SSD hard disk
  • 22. Solutions – High Velocity ● Play is a high velocity Framework by default ● Using async/non-blocking data-access library: ReactiveMongo ● Futures and Promises ● Iteratees (for rendering huge data with minimum resource usage: RAM or CPU) ● Everything is perfect; even didn't need caching!
  • 23. Solutions – NoSQL ● Manage relationships asynchronously – Get fair information → Get registration information → Get basic information → … ● All non-block – Repeat data ● Fairs in which the exhibitor is registered ● Registered exhibitors for each fair – Search ● Generate keywords on CUD, don't use RegEx ● NoSQL is not suitable for a system with complex relationships ● Reports are painful but amazingly fast – Need a job to collect data into another collection – For real-time reports, data should be collected on CUD events
  • 24. Solutions - Integration ● Scala is on top of JVM with a huge high quality libraries – I needed Rijndael-256 which is not common and is not implemented in Java standard libraries ● Bouncycastle ● Also used – Play's WS as web service client – Scalaxb to generate WSDL classes (they didn't support REST) – Again everything is async
  • 25. Libraries and Tools - 100% Free● OS – Linux (server and development) ● IDE and Tools – Activator – Scala IDE – RoboMongo – Git ● DB – MongoDB ● Front-end Server – Nginx ● Framework Libraries – Play Framework – ReactiveMongo – Macwire (compile-time DI) – Silhouette (authentication) – Scrimage (image resizing) – Persianutils by Bahman Movaghar – Bouncycastle – Xcala; my own application library – etc.
  • 26. Well Done! ● Common – Full-stack development – Full async architecture (top to bottom) – Very good RAM usage except for exporting Excel files ● TIBF Website – Less than 100ms responses on peak times ● TIBF Registration System – Most of the publishers were happy – Most of the operators were happy – I was agile to implement real-time requests in minutes or hours ● TIBF Coupon System – Boom! Things didn't go well – Although about 5,000 successful purchases have been done in a couple of hours...
  • 27. Failure ● After lunching the TIBF coupon website, all websites seemed down ● but the system load was OK! ● Incomplete payments started to show up – Verified payments without having invoices marked as paid – Double payments ● Stress – Loneliness – Failure
  • 28. Failure I Failed :((((( ● Bad feeling about Scala ● Feels like someone is pouring ice water on my head ● A weird kind of relief ● Everything got quiet
  • 29. Didn't Give Up ● Took a break, got relaxed and focused ● Checked the bandwidth ● Checked the server disk speed ● Checked the logs – Nginx: Too many open files ● Checked the connections – netstat -na | grep :80 | wc -l ● About 4,000 open connections! ● Google – Default OS limitation for open files is 4,000 – There is a simple solution for “Too many open files” – It was a victory! I could have reach to the OS limits on a small server
  • 30. Fix ● Add “fs.file-max” to “/etc/sysctl.conf” ● Set soft and hard limits in “/etc/security/limits.conf” for Nginx and the user by which Play apps are running ● Set “worker_rlimit_nofile” in “/usr/local/nginx/conf/nginx.conf” ● The server begin responding but the RAM was still too low – Exporting Excel files for operators eats the RAM – The laptop I used for this presentation has more RAM than the server did (6GB) 6GB 3M$
  • 31. Final Relief ● They gave me a giant server – 120 Core – 128 GB of RAM ● I used at most lest than 1% of this server resources! ● Although again I increased the default OS limitation on number of open files ● And their network got a serious problem
  • 35. Thank you Build amazing things with your lovely tools Iran-SUG => Iranian Scala User Group Amir Karimi <[email protected]> @4m1rk www.dev-frame.com