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

What's hot

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

What's hot (20)

CFWheels - Pragmatic, Beautiful Code
CFWheels - Pragmatic, Beautiful CodeCFWheels - Pragmatic, Beautiful Code
CFWheels - Pragmatic, Beautiful Code
 
IoT and developer chances
IoT and developer chancesIoT and developer chances
IoT and developer chances
 
Big Data! Great! Now What? #SymfonyCon 2014
Big Data! Great! Now What? #SymfonyCon 2014Big Data! Great! Now What? #SymfonyCon 2014
Big Data! Great! Now What? #SymfonyCon 2014
 
4Developers 2015: Scaling LAMP doesn't have to suck - Sebastian Grodzicki
4Developers 2015: Scaling LAMP doesn't have to suck - Sebastian Grodzicki4Developers 2015: Scaling LAMP doesn't have to suck - Sebastian Grodzicki
4Developers 2015: Scaling LAMP doesn't have to suck - Sebastian Grodzicki
 
Redis Everywhere - Sunshine PHP
Redis Everywhere - Sunshine PHPRedis Everywhere - Sunshine PHP
Redis Everywhere - Sunshine PHP
 
Automating Your Daily Tasks with Scripting - RubyConf 2015 Taiwan
Automating Your Daily Tasks with Scripting - RubyConf 2015 TaiwanAutomating Your Daily Tasks with Scripting - RubyConf 2015 Taiwan
Automating Your Daily Tasks with Scripting - RubyConf 2015 Taiwan
 
A Gentle Introduction to Functions-as-a-Service
A Gentle Introduction to Functions-as-a-ServiceA Gentle Introduction to Functions-as-a-Service
A Gentle Introduction to Functions-as-a-Service
 
High-performance high-availability Plone
High-performance high-availability PloneHigh-performance high-availability Plone
High-performance high-availability Plone
 
About Caching
About CachingAbout Caching
About Caching
 
Redis : Database, cache, pub/sub and more at Jelly button games
Redis : Database, cache, pub/sub and more at Jelly button gamesRedis : Database, cache, pub/sub and more at Jelly button games
Redis : Database, cache, pub/sub and more at Jelly button games
 
Messaging, interoperability and log aggregation - a new framework
Messaging, interoperability and log aggregation - a new frameworkMessaging, interoperability and log aggregation - a new framework
Messaging, interoperability and log aggregation - a new framework
 
Modern software architectures - PHP UK Conference 2015
Modern software architectures - PHP UK Conference 2015Modern software architectures - PHP UK Conference 2015
Modern software architectures - PHP UK Conference 2015
 
Beyond Apache: Faster Web Servers
Beyond Apache: Faster Web ServersBeyond Apache: Faster Web Servers
Beyond Apache: Faster Web Servers
 
Enterprise messaging
Enterprise messagingEnterprise messaging
Enterprise messaging
 
Ship It ! with Ruby/ Rails Ecosystem
Ship It ! with Ruby/ Rails EcosystemShip It ! with Ruby/ Rails Ecosystem
Ship It ! with Ruby/ Rails Ecosystem
 
Riak at Posterous
Riak at PosterousRiak at Posterous
Riak at Posterous
 
Cache hcm-topdev
Cache hcm-topdevCache hcm-topdev
Cache hcm-topdev
 
Server Check.in case study - Drupal and Node.js
Server Check.in case study - Drupal and Node.jsServer Check.in case study - Drupal and Node.js
Server Check.in case study - Drupal and Node.js
 
SSJS, NoSQL, GAE and AppengineJS
SSJS, NoSQL, GAE and AppengineJSSSJS, NoSQL, GAE and AppengineJS
SSJS, NoSQL, GAE and AppengineJS
 
Social Connections 2015 CrossWorlds and Domino
Social Connections 2015 CrossWorlds and DominoSocial Connections 2015 CrossWorlds and Domino
Social Connections 2015 CrossWorlds and Domino
 

Similar to Real-world Experiences in Scala

Virtualizing Development
Virtualizing DevelopmentVirtualizing Development
Virtualizing Development
Adam Culp
 
kranonit S06E01 Игорь Цинько: High load
kranonit S06E01 Игорь Цинько: High loadkranonit S06E01 Игорь Цинько: High load
kranonit S06E01 Игорь Цинько: High loadKrivoy Rog IT Community
 
Ansible deployment
Ansible deploymentAnsible deployment
Ansible deployment
Didiet A. Pambudiono
 
Proper Care and Feeding of a MySQL Database for Busy Linux Administrators
Proper Care and Feeding of a MySQL Database for Busy Linux AdministratorsProper Care and Feeding of a MySQL Database for Busy Linux Administrators
Proper Care and Feeding of a MySQL Database for Busy Linux Administrators
Dave Stokes
 
Drupal Performance and Scaling
Drupal Performance and ScalingDrupal Performance and Scaling
Drupal Performance and ScalingGerald Villorente
 
The Proper Care and Feeding of a MySQL Database for Busy Linux Admins -- SCaL...
The Proper Care and Feeding of a MySQL Database for Busy Linux Admins -- SCaL...The Proper Care and Feeding of a MySQL Database for Busy Linux Admins -- SCaL...
The Proper Care and Feeding of a MySQL Database for Busy Linux Admins -- SCaL...
Dave Stokes
 
Screaming Fast Wpmu
Screaming Fast WpmuScreaming Fast Wpmu
Screaming Fast Wpmudjcp
 
Linuxfest Northwest Proper Care and Feeding Of a MySQL for Busy Linux Admins
Linuxfest Northwest Proper Care and Feeding Of a MySQL for Busy Linux AdminsLinuxfest Northwest Proper Care and Feeding Of a MySQL for Busy Linux Admins
Linuxfest Northwest Proper Care and Feeding Of a MySQL for Busy Linux Admins
Dave Stokes
 
Deploying Perl apps on dotCloud
Deploying Perl apps on dotCloudDeploying Perl apps on dotCloud
Deploying Perl apps on dotCloud
daoswald
 
Cloud arch patterns
Cloud arch patternsCloud arch patterns
Cloud arch patterns
Corey Huinker
 
Backend & Frontend architecture scalability & websockets
Backend & Frontend architecture scalability & websocketsBackend & Frontend architecture scalability & websockets
Backend & Frontend architecture scalability & websockets
Anne Jan Brouwer
 
Netty training
Netty trainingNetty training
Go with the Flow - A Guide to a WordPress Workflow
Go with the Flow - A Guide to a WordPress WorkflowGo with the Flow - A Guide to a WordPress Workflow
Go with the Flow - A Guide to a WordPress Workflow
Ann Cascarano
 
DrupalCampLA 2014 - Drupal backend performance and scalability
DrupalCampLA 2014 - Drupal backend performance and scalabilityDrupalCampLA 2014 - Drupal backend performance and scalability
DrupalCampLA 2014 - Drupal backend performance and scalability
cherryhillco
 
Netty training
Netty trainingNetty training
Netty training
Marcelo Serpa
 
[HKOSCON][20180616][Containerized High Availability Virtual Hosting Deploymen...
[HKOSCON][20180616][Containerized High Availability Virtual Hosting Deploymen...[HKOSCON][20180616][Containerized High Availability Virtual Hosting Deploymen...
[HKOSCON][20180616][Containerized High Availability Virtual Hosting Deploymen...
Wong Hoi Sing Edison
 
Beyond Puppet
Beyond PuppetBeyond Puppet
Beyond Puppet
Kris Buytaert
 
Go with the Flow - A Guide to a WordPress Workflow
Go with the Flow - A Guide to a WordPress WorkflowGo with the Flow - A Guide to a WordPress Workflow
Go with the Flow - A Guide to a WordPress Workflow
Ann Cascarano
 
Openstack India May Meetup
Openstack India May MeetupOpenstack India May Meetup
Openstack India May MeetupDeepak Garg
 
The Professional Programmer
The Professional ProgrammerThe Professional Programmer
The Professional Programmer
Dave Cross
 

Similar to Real-world Experiences in Scala (20)

Virtualizing Development
Virtualizing DevelopmentVirtualizing Development
Virtualizing Development
 
kranonit S06E01 Игорь Цинько: High load
kranonit S06E01 Игорь Цинько: High loadkranonit S06E01 Игорь Цинько: High load
kranonit S06E01 Игорь Цинько: High load
 
Ansible deployment
Ansible deploymentAnsible deployment
Ansible deployment
 
Proper Care and Feeding of a MySQL Database for Busy Linux Administrators
Proper Care and Feeding of a MySQL Database for Busy Linux AdministratorsProper Care and Feeding of a MySQL Database for Busy Linux Administrators
Proper Care and Feeding of a MySQL Database for Busy Linux Administrators
 
Drupal Performance and Scaling
Drupal Performance and ScalingDrupal Performance and Scaling
Drupal Performance and Scaling
 
The Proper Care and Feeding of a MySQL Database for Busy Linux Admins -- SCaL...
The Proper Care and Feeding of a MySQL Database for Busy Linux Admins -- SCaL...The Proper Care and Feeding of a MySQL Database for Busy Linux Admins -- SCaL...
The Proper Care and Feeding of a MySQL Database for Busy Linux Admins -- SCaL...
 
Screaming Fast Wpmu
Screaming Fast WpmuScreaming Fast Wpmu
Screaming Fast Wpmu
 
Linuxfest Northwest Proper Care and Feeding Of a MySQL for Busy Linux Admins
Linuxfest Northwest Proper Care and Feeding Of a MySQL for Busy Linux AdminsLinuxfest Northwest Proper Care and Feeding Of a MySQL for Busy Linux Admins
Linuxfest Northwest Proper Care and Feeding Of a MySQL for Busy Linux Admins
 
Deploying Perl apps on dotCloud
Deploying Perl apps on dotCloudDeploying Perl apps on dotCloud
Deploying Perl apps on dotCloud
 
Cloud arch patterns
Cloud arch patternsCloud arch patterns
Cloud arch patterns
 
Backend & Frontend architecture scalability & websockets
Backend & Frontend architecture scalability & websocketsBackend & Frontend architecture scalability & websockets
Backend & Frontend architecture scalability & websockets
 
Netty training
Netty trainingNetty training
Netty training
 
Go with the Flow - A Guide to a WordPress Workflow
Go with the Flow - A Guide to a WordPress WorkflowGo with the Flow - A Guide to a WordPress Workflow
Go with the Flow - A Guide to a WordPress Workflow
 
DrupalCampLA 2014 - Drupal backend performance and scalability
DrupalCampLA 2014 - Drupal backend performance and scalabilityDrupalCampLA 2014 - Drupal backend performance and scalability
DrupalCampLA 2014 - Drupal backend performance and scalability
 
Netty training
Netty trainingNetty training
Netty training
 
[HKOSCON][20180616][Containerized High Availability Virtual Hosting Deploymen...
[HKOSCON][20180616][Containerized High Availability Virtual Hosting Deploymen...[HKOSCON][20180616][Containerized High Availability Virtual Hosting Deploymen...
[HKOSCON][20180616][Containerized High Availability Virtual Hosting Deploymen...
 
Beyond Puppet
Beyond PuppetBeyond Puppet
Beyond Puppet
 
Go with the Flow - A Guide to a WordPress Workflow
Go with the Flow - A Guide to a WordPress WorkflowGo with the Flow - A Guide to a WordPress Workflow
Go with the Flow - A Guide to a WordPress Workflow
 
Openstack India May Meetup
Openstack India May MeetupOpenstack India May Meetup
Openstack India May Meetup
 
The Professional Programmer
The Professional ProgrammerThe Professional Programmer
The Professional Programmer
 

Recently uploaded

Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024
Paco van Beckhoven
 
Enhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdfEnhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdf
Globus
 
A Comprehensive Look at Generative AI in Retail App Testing.pdf
A Comprehensive Look at Generative AI in Retail App Testing.pdfA Comprehensive Look at Generative AI in Retail App Testing.pdf
A Comprehensive Look at Generative AI in Retail App Testing.pdf
kalichargn70th171
 
Accelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with PlatformlessAccelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with Platformless
WSO2
 
Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604
Fermin Galan
 
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
informapgpstrackings
 
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Globus
 
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERRORTROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
Tier1 app
 
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.ILBeyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Natan Silnitsky
 
How to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good PracticesHow to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good Practices
Globus
 
2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx
Georgi Kodinov
 
top nidhi software solution freedownload
top nidhi software solution freedownloadtop nidhi software solution freedownload
top nidhi software solution freedownload
vrstrong314
 
Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology SolutionsProsigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns
 
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Mind IT Systems
 
Using IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New ZealandUsing IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New Zealand
IES VE
 
Cyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdfCyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdf
Cyanic lab
 
Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024
Globus
 
Enterprise Resource Planning System in Telangana
Enterprise Resource Planning System in TelanganaEnterprise Resource Planning System in Telangana
Enterprise Resource Planning System in Telangana
NYGGS Automation Suite
 
GlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote sessionGlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote session
Globus
 
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Shahin Sheidaei
 

Recently uploaded (20)

Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024
 
Enhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdfEnhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdf
 
A Comprehensive Look at Generative AI in Retail App Testing.pdf
A Comprehensive Look at Generative AI in Retail App Testing.pdfA Comprehensive Look at Generative AI in Retail App Testing.pdf
A Comprehensive Look at Generative AI in Retail App Testing.pdf
 
Accelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with PlatformlessAccelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with Platformless
 
Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604
 
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
 
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
 
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERRORTROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
 
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.ILBeyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
 
How to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good PracticesHow to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good Practices
 
2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx
 
top nidhi software solution freedownload
top nidhi software solution freedownloadtop nidhi software solution freedownload
top nidhi software solution freedownload
 
Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology SolutionsProsigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology Solutions
 
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
 
Using IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New ZealandUsing IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New Zealand
 
Cyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdfCyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdf
 
Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024
 
Enterprise Resource Planning System in Telangana
Enterprise Resource Planning System in TelanganaEnterprise Resource Planning System in Telangana
Enterprise Resource Planning System in Telangana
 
GlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote sessionGlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote session
 
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
 

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 <a.karimi.k@gmail.com> @4m1rk www.dev-frame.com