SlideShare une entreprise Scribd logo
1  sur  28
Nexthink Library
in Scala
Implementation & Techniques
Replacing a Ruby on Rails Application with
Scala / Spray
Matthew Farwell
Senior Developer @ Nexthink in Lausanne
Java / Scala / JVM
Project lead on Scalastyle, the style checker for Scala
Contributor to other open source projects, JUnit
Co-author of “sbt in Action” with Josh Suereth
The Nexthink Library
The Nexthink Library
Project Goals
To rewrite the existing Ruby on Rails Library
To make it more ‘mainstream’ in the company
Increase the truck number
Have adequate performance for the future.
Assess technologies:
– Spray for web container, async, non-blocking
– Slick for database access (instead of Hibernate)
– Gatling for performance tests
– Angular JS for front end
Existing solution
Split into two parts:
API used by Finder and Portal, both GET and POST
5 different types of request
Administration section, for updating content
Requirements
– For the API, it must do exactly the same as the
legacy.
– The admin section can be improved if we want
Approach
A single rest server which serves both the API and the
admin screens (Spray)
The admin screens use Angular JS, which themselves
use the REST APIs
Server is stateless, therefore no sessions, etc.
Text search uses Lucene
Spray
Spray is a DSL to describe a REST API along with the
actions. It is a mixture of directives and actions:
path("1" / "ping") {
get {
respondWithMediaType(`application/json`) {
complete {
Ping(Settings.config.hostname, databaseOk())
}
}
}
}
implicit val pingFormat = jsonFormat2(Ping)
Spray
It makes things easy to do asynchronously and non-
blocking:
complete {
future {
val u = entityService.update(id, obj, user)
future { LibraryApi.refreshCache }
u
}
}
complete {
pipeline(Get("http://google.com"))
}
Testing with comparison
API Testing
We can test the new library by comparing directly with
the legacy library. So how do we generate the test
cases? We can:
use the access log for the legacy library to get a typical set of
requests
generate test cases using Scalacheck
Scalacheck
Scalacheck allows you to generate data for tests
It can generate random structured data
It then calls the Method Under Test and compares the result
using properties
It can then ‘reduce’ the use case to the smallest size which fails
In our case, we only use the generation methods
Scalacheck example
This generates one type of request:
val gen: Gen[Parameters] = for {
elementTypes <- Gen.oneOf("alert", "investigation")
tag <- Gen.containerOf[List, String](
Gen.oneOf("", "cloud", "security"))
version <- Gen.oneOf("", "3.1", "4", "5")
} yield Parameters("categories", 100, tag, elementTypes,
version, license)
We run this 5000 times per type of request for our basic tests.
Scalacheck is very good for exploring an API and finding edge cases.
Proxy/Comparison
Proxy/Comparison
The new library proxies the legacy. When we call the
legacy (non-blocking), we return those results.
When we return the results, we asynchronously compare
the results with the new library.
We can put this into production without fear
complete {
val f = pipeline(Get(legacyUrl(params)))
f onComplete { result =>
compare(result, localApi(params))
}
f
}
Proxy/Comparison
If there is a comparison failure, we store the parameters
that failed, which we can access from the FE.
We record all of the parameters from a GET or a POST.
We can also replay a failure
This approach means that we have to share the
database – so we didn't change it at all.
We had different comparison strategies depending upon
the type of API call.
Some numbers
Legacy RoR
~3400 lines (.rb, .erb, .xml.builder)
New:
~3400 lines Scala (500 lines comparison/proxy)
~1000 lines JavaScript (Angular JS)
~650 lines HTML
Spring app (similar) backend with DB: ~9000 lines Java
Frontend (GWT): ~16000 lines Java
Performance Tests – Gatling
Define a scenario:
val scn = scenario("basic usage")
.group("search") {
repeat(100) {
exec(http("google").get("http://google.com"))
.pause(0 milliseconds, 2 milliseconds)
.exec(http("yahoo").get("http://yahoo.com"))
}
}
Performance Tests – Gatling
Execute it:
setUp(scn.inject(ramp(10 users) over (10 seconds)))
.protocols(httpConf)
.assertions(
global.successfulRequests.percent.is(100),
details("search"/"google").responseTime.max.lessThan(100),
details("search"/"yahoo").responseTime.max.lessThan(100))
Gatling
Performance – RoR baseline
5 Users, 5 times, 10 requests == 250 requests
Total time: 227 seconds, req/s = 1
Caveats: unstable setup, production (single request) was
faster x 10
Mean Max
search 7600 8900
featured 2500 3200
copy 6300 7000
Performance – New
5 Users, 5 times, 10 requests == 250 requests
Total time: 5 seconds, req/s = 50
Mean Max
search 11 30
featured 5 10
copy 0 0
Performance – New
100 Users, 100 times, 10 requests == 100,000 requests
Total time: 28 seconds, req/s = 3571
3571 req/s == 300,000,000 / day
Mean Max
search 33 660
featured 24 500
copy 22 460
Performance – New
1000 Users, 100 times, 10 requests == 1,000,000 requests
Total time: 280 seconds, req/s = 3564
Required: 150-160k / day
We can support 1 day’s traffic in < 1 minute. We have
room for expansion :-)
Mean Max
search 383 15400
featured 259 23510
copy 260 33310
Some interesting numbers
Number of failures during performance tests: 0
This means that the system is very stable.
The throughput for 100 concurrent users (3571 req/s) is
about the same as for 1000 concurrent users (3564
req/s), but each request takes longer when there are
1000 concurrent users.
This is due to back pressure.
Production
Production: April 2014
Proxies were in place 6-8 weeks
Bugs found:
1 - incorrect version (attribute value) returned
2 – Finder was using empty url as a ping
3 – incorrect data returned (cause: data in database)
4 – encoding problem
Conclusion
Scala (language and tools)
compilation slow, tooling great (sbt & worksheet)
Spray
easy to use, simple to extend, no real ‘magic’
Scalacheck
very good for exploring an API, and finding edge cases, good for
data oriented testing
Slick
– easy to use, we were only doing simple things, but very similar
to working with direct SQL.
Conclusion
Angular JS
Great. Better than some of the other solutions we've had.
Async / non-blocking
Fairly easy to manage in Scala, harder in Java. Harder when
dealing with databases and non-web services.
Gatling
Great. Simple and easy. Miles better than the alternatives
(JMeter for example)
Questions?
Twitter: @matthewfarwell
Scalastyle: @scalastyle http://www.scalastyle.org
Sbt in Action:
https://www.manning.com/books/sbt-in-action
Nexthink are hiring! http://www.nexthink.com

Contenu connexe

Tendances

vJUG - The JavaFX Ecosystem
vJUG - The JavaFX EcosystemvJUG - The JavaFX Ecosystem
vJUG - The JavaFX EcosystemAndres Almiray
 
APIs: A Better Alternative to Page Objects
APIs: A Better Alternative to Page ObjectsAPIs: A Better Alternative to Page Objects
APIs: A Better Alternative to Page ObjectsSauce Labs
 
Spring Boot and REST API
Spring Boot and REST APISpring Boot and REST API
Spring Boot and REST API07.pallav
 
Laravel Forge: Hello World to Hello Production
Laravel Forge: Hello World to Hello ProductionLaravel Forge: Hello World to Hello Production
Laravel Forge: Hello World to Hello ProductionJoe Ferguson
 
MidwestPHP 2016 - Adventures in Laravel 5
MidwestPHP 2016 - Adventures in Laravel 5 MidwestPHP 2016 - Adventures in Laravel 5
MidwestPHP 2016 - Adventures in Laravel 5 Joe Ferguson
 
Join the darkside: Selenium testing with Nightwatch.js
Join the darkside: Selenium testing with Nightwatch.jsJoin the darkside: Selenium testing with Nightwatch.js
Join the darkside: Selenium testing with Nightwatch.jsSeth McLaughlin
 
SenchaCon 2016: Learn the Top 10 Best ES2015 Features - Lee Boonstra
SenchaCon 2016: Learn the Top 10 Best ES2015 Features - Lee Boonstra  SenchaCon 2016: Learn the Top 10 Best ES2015 Features - Lee Boonstra
SenchaCon 2016: Learn the Top 10 Best ES2015 Features - Lee Boonstra Sencha
 
Intoduction to Play Framework
Intoduction to Play FrameworkIntoduction to Play Framework
Intoduction to Play FrameworkKnoldus Inc.
 
Intro to testing Javascript with jasmine
Intro to testing Javascript with jasmineIntro to testing Javascript with jasmine
Intro to testing Javascript with jasmineTimothy Oxley
 
Test automation with Cucumber-JVM
Test automation with Cucumber-JVMTest automation with Cucumber-JVM
Test automation with Cucumber-JVMAlan Parkinson
 
Angularjs - Unit testing introduction
Angularjs - Unit testing introductionAngularjs - Unit testing introduction
Angularjs - Unit testing introductionNir Kaufman
 
Testing Code.org's Interactive CS Curriculum
Testing Code.org's Interactive CS CurriculumTesting Code.org's Interactive CS Curriculum
Testing Code.org's Interactive CS CurriculumBrian Jordan
 
Spring boot - an introduction
Spring boot - an introductionSpring boot - an introduction
Spring boot - an introductionJonathan Holloway
 
Introduction to Spring Boot
Introduction to Spring BootIntroduction to Spring Boot
Introduction to Spring BootTrey Howard
 
Spring boot introduction
Spring boot introductionSpring boot introduction
Spring boot introductionRasheed Waraich
 
Front-End Testing: Demystified
Front-End Testing: DemystifiedFront-End Testing: Demystified
Front-End Testing: DemystifiedSeth McLaughlin
 
jQuery Proven Performance Tips & Tricks
jQuery Proven Performance Tips & TricksjQuery Proven Performance Tips & Tricks
jQuery Proven Performance Tips & TricksAddy Osmani
 
Automated testing with Drupal
Automated testing with DrupalAutomated testing with Drupal
Automated testing with DrupalPromet Source
 

Tendances (20)

vJUG - The JavaFX Ecosystem
vJUG - The JavaFX EcosystemvJUG - The JavaFX Ecosystem
vJUG - The JavaFX Ecosystem
 
APIs: A Better Alternative to Page Objects
APIs: A Better Alternative to Page ObjectsAPIs: A Better Alternative to Page Objects
APIs: A Better Alternative to Page Objects
 
Selenium Overview
Selenium OverviewSelenium Overview
Selenium Overview
 
Spring Boot and REST API
Spring Boot and REST APISpring Boot and REST API
Spring Boot and REST API
 
Laravel Forge: Hello World to Hello Production
Laravel Forge: Hello World to Hello ProductionLaravel Forge: Hello World to Hello Production
Laravel Forge: Hello World to Hello Production
 
MidwestPHP 2016 - Adventures in Laravel 5
MidwestPHP 2016 - Adventures in Laravel 5 MidwestPHP 2016 - Adventures in Laravel 5
MidwestPHP 2016 - Adventures in Laravel 5
 
Join the darkside: Selenium testing with Nightwatch.js
Join the darkside: Selenium testing with Nightwatch.jsJoin the darkside: Selenium testing with Nightwatch.js
Join the darkside: Selenium testing with Nightwatch.js
 
SenchaCon 2016: Learn the Top 10 Best ES2015 Features - Lee Boonstra
SenchaCon 2016: Learn the Top 10 Best ES2015 Features - Lee Boonstra  SenchaCon 2016: Learn the Top 10 Best ES2015 Features - Lee Boonstra
SenchaCon 2016: Learn the Top 10 Best ES2015 Features - Lee Boonstra
 
Intoduction to Play Framework
Intoduction to Play FrameworkIntoduction to Play Framework
Intoduction to Play Framework
 
Intro to testing Javascript with jasmine
Intro to testing Javascript with jasmineIntro to testing Javascript with jasmine
Intro to testing Javascript with jasmine
 
Test automation with Cucumber-JVM
Test automation with Cucumber-JVMTest automation with Cucumber-JVM
Test automation with Cucumber-JVM
 
Angularjs - Unit testing introduction
Angularjs - Unit testing introductionAngularjs - Unit testing introduction
Angularjs - Unit testing introduction
 
Testing Code.org's Interactive CS Curriculum
Testing Code.org's Interactive CS CurriculumTesting Code.org's Interactive CS Curriculum
Testing Code.org's Interactive CS Curriculum
 
Spring boot - an introduction
Spring boot - an introductionSpring boot - an introduction
Spring boot - an introduction
 
Introduction to Spring Boot
Introduction to Spring BootIntroduction to Spring Boot
Introduction to Spring Boot
 
Spring boot introduction
Spring boot introductionSpring boot introduction
Spring boot introduction
 
Front-End Testing: Demystified
Front-End Testing: DemystifiedFront-End Testing: Demystified
Front-End Testing: Demystified
 
Intro to Laravel
Intro to LaravelIntro to Laravel
Intro to Laravel
 
jQuery Proven Performance Tips & Tricks
jQuery Proven Performance Tips & TricksjQuery Proven Performance Tips & Tricks
jQuery Proven Performance Tips & Tricks
 
Automated testing with Drupal
Automated testing with DrupalAutomated testing with Drupal
Automated testing with Drupal
 

En vedette

Mobile and apps in corporate communications
Mobile and apps in corporate communicationsMobile and apps in corporate communications
Mobile and apps in corporate communicationsComprend
 
Volunteering work opportunities in Thailand | Volunteering Solutions
Volunteering work opportunities in Thailand | Volunteering SolutionsVolunteering work opportunities in Thailand | Volunteering Solutions
Volunteering work opportunities in Thailand | Volunteering SolutionsVolunteering Solutions
 
10 Best Ways to Engage and Connect with Employees
10 Best Ways to Engage and Connect with Employees10 Best Ways to Engage and Connect with Employees
10 Best Ways to Engage and Connect with EmployeesDavid Grossman
 
Staying ahead of the curve (Digital Corporate Communications)
Staying ahead of the curve (Digital Corporate Communications)Staying ahead of the curve (Digital Corporate Communications)
Staying ahead of the curve (Digital Corporate Communications)Staffan Lindgren
 
Manufacturing pov jeff green 2016 v2
Manufacturing pov jeff green 2016 v2Manufacturing pov jeff green 2016 v2
Manufacturing pov jeff green 2016 v2Jeff Green
 
Sitrion ONE Tour - Mobile Moments - Dec 2014
Sitrion ONE Tour - Mobile Moments - Dec 2014Sitrion ONE Tour - Mobile Moments - Dec 2014
Sitrion ONE Tour - Mobile Moments - Dec 2014Sitrion
 
Take a Trip with Employee Advocacy: How TripIt Relies on Employees to Promote...
Take a Trip with Employee Advocacy: How TripIt Relies on Employees to Promote...Take a Trip with Employee Advocacy: How TripIt Relies on Employees to Promote...
Take a Trip with Employee Advocacy: How TripIt Relies on Employees to Promote...SocialChorus
 
Millennials in the Workplace: It's Time to Think Differently About Employee C...
Millennials in the Workplace: It's Time to Think Differently About Employee C...Millennials in the Workplace: It's Time to Think Differently About Employee C...
Millennials in the Workplace: It's Time to Think Differently About Employee C...Navera
 
Volunteering opportunities in india | Volunteering Solutions
Volunteering opportunities in india | Volunteering SolutionsVolunteering opportunities in india | Volunteering Solutions
Volunteering opportunities in india | Volunteering SolutionsVolunteering Solutions
 
MiTiN 2013 Keynote in Detroit Michigan
MiTiN 2013 Keynote in Detroit MichiganMiTiN 2013 Keynote in Detroit Michigan
MiTiN 2013 Keynote in Detroit MichiganKirti Vashee
 
Knowledge transfers within the Organizations
Knowledge transfers within the OrganizationsKnowledge transfers within the Organizations
Knowledge transfers within the OrganizationsDieter Hovorka
 
Internal Communication as a key competency of Customer Centricity and Custome...
Internal Communication as a key competency of Customer Centricity and Custome...Internal Communication as a key competency of Customer Centricity and Custome...
Internal Communication as a key competency of Customer Centricity and Custome...Alexander Stoter
 
Nexthink-See your infrastructure as never before!!
Nexthink-See your infrastructure as never before!!Nexthink-See your infrastructure as never before!!
Nexthink-See your infrastructure as never before!!rolandpiedl
 
How Reebok Uses Employee Generated Content to Amplify Advocacy
How Reebok Uses Employee Generated Content to Amplify Advocacy How Reebok Uses Employee Generated Content to Amplify Advocacy
How Reebok Uses Employee Generated Content to Amplify Advocacy SocialChorus
 
Measuring employee engagement
Measuring employee engagementMeasuring employee engagement
Measuring employee engagementKevin Ruck
 
Closing the Gap: A Look At Technology in Corporate Communications
Closing the Gap: A Look At Technology in Corporate CommunicationsClosing the Gap: A Look At Technology in Corporate Communications
Closing the Gap: A Look At Technology in Corporate CommunicationsSocialChorus
 

En vedette (20)

Mobile and apps in corporate communications
Mobile and apps in corporate communicationsMobile and apps in corporate communications
Mobile and apps in corporate communications
 
Volunteering work opportunities in Thailand | Volunteering Solutions
Volunteering work opportunities in Thailand | Volunteering SolutionsVolunteering work opportunities in Thailand | Volunteering Solutions
Volunteering work opportunities in Thailand | Volunteering Solutions
 
10 Best Ways to Engage and Connect with Employees
10 Best Ways to Engage and Connect with Employees10 Best Ways to Engage and Connect with Employees
10 Best Ways to Engage and Connect with Employees
 
Staying ahead of the curve (Digital Corporate Communications)
Staying ahead of the curve (Digital Corporate Communications)Staying ahead of the curve (Digital Corporate Communications)
Staying ahead of the curve (Digital Corporate Communications)
 
Modelos de negócios - Aula 1
Modelos de negócios - Aula 1Modelos de negócios - Aula 1
Modelos de negócios - Aula 1
 
Leadership Insights From TED 2016: Dream
Leadership Insights From TED 2016: DreamLeadership Insights From TED 2016: Dream
Leadership Insights From TED 2016: Dream
 
Manufacturing pov jeff green 2016 v2
Manufacturing pov jeff green 2016 v2Manufacturing pov jeff green 2016 v2
Manufacturing pov jeff green 2016 v2
 
W4hy
W4hyW4hy
W4hy
 
Sitrion ONE Tour - Mobile Moments - Dec 2014
Sitrion ONE Tour - Mobile Moments - Dec 2014Sitrion ONE Tour - Mobile Moments - Dec 2014
Sitrion ONE Tour - Mobile Moments - Dec 2014
 
Take a Trip with Employee Advocacy: How TripIt Relies on Employees to Promote...
Take a Trip with Employee Advocacy: How TripIt Relies on Employees to Promote...Take a Trip with Employee Advocacy: How TripIt Relies on Employees to Promote...
Take a Trip with Employee Advocacy: How TripIt Relies on Employees to Promote...
 
Millennials in the Workplace: It's Time to Think Differently About Employee C...
Millennials in the Workplace: It's Time to Think Differently About Employee C...Millennials in the Workplace: It's Time to Think Differently About Employee C...
Millennials in the Workplace: It's Time to Think Differently About Employee C...
 
Volunteering opportunities in india | Volunteering Solutions
Volunteering opportunities in india | Volunteering SolutionsVolunteering opportunities in india | Volunteering Solutions
Volunteering opportunities in india | Volunteering Solutions
 
Angel hack presentation
Angel hack presentationAngel hack presentation
Angel hack presentation
 
MiTiN 2013 Keynote in Detroit Michigan
MiTiN 2013 Keynote in Detroit MichiganMiTiN 2013 Keynote in Detroit Michigan
MiTiN 2013 Keynote in Detroit Michigan
 
Knowledge transfers within the Organizations
Knowledge transfers within the OrganizationsKnowledge transfers within the Organizations
Knowledge transfers within the Organizations
 
Internal Communication as a key competency of Customer Centricity and Custome...
Internal Communication as a key competency of Customer Centricity and Custome...Internal Communication as a key competency of Customer Centricity and Custome...
Internal Communication as a key competency of Customer Centricity and Custome...
 
Nexthink-See your infrastructure as never before!!
Nexthink-See your infrastructure as never before!!Nexthink-See your infrastructure as never before!!
Nexthink-See your infrastructure as never before!!
 
How Reebok Uses Employee Generated Content to Amplify Advocacy
How Reebok Uses Employee Generated Content to Amplify Advocacy How Reebok Uses Employee Generated Content to Amplify Advocacy
How Reebok Uses Employee Generated Content to Amplify Advocacy
 
Measuring employee engagement
Measuring employee engagementMeasuring employee engagement
Measuring employee engagement
 
Closing the Gap: A Look At Technology in Corporate Communications
Closing the Gap: A Look At Technology in Corporate CommunicationsClosing the Gap: A Look At Technology in Corporate Communications
Closing the Gap: A Look At Technology in Corporate Communications
 

Similaire à Nexthink Library - replacing a ruby on rails application with Scala and Spray

Extending Oracle E-Business Suite with Ruby on Rails
Extending Oracle E-Business Suite with Ruby on RailsExtending Oracle E-Business Suite with Ruby on Rails
Extending Oracle E-Business Suite with Ruby on RailsRaimonds Simanovskis
 
Getting started with Apollo Client and GraphQL
Getting started with Apollo Client and GraphQLGetting started with Apollo Client and GraphQL
Getting started with Apollo Client and GraphQLMorgan Dedmon
 
RSpec and Rails
RSpec and RailsRSpec and Rails
RSpec and RailsAlan Hecht
 
Overhauling a database engine in 2 months
Overhauling a database engine in 2 monthsOverhauling a database engine in 2 months
Overhauling a database engine in 2 monthsMax Neunhöffer
 
How easy (or hard) it is to monitor your graph ql service performance
How easy (or hard) it is to monitor your graph ql service performanceHow easy (or hard) it is to monitor your graph ql service performance
How easy (or hard) it is to monitor your graph ql service performanceLuca Mattia Ferrari
 
Unit testing of spark applications
Unit testing of spark applicationsUnit testing of spark applications
Unit testing of spark applicationsKnoldus Inc.
 
Expanding beyond SPL -- More language support in IBM Streams V4.1
Expanding beyond SPL -- More language support in IBM Streams V4.1Expanding beyond SPL -- More language support in IBM Streams V4.1
Expanding beyond SPL -- More language support in IBM Streams V4.1lisanl
 
Where is my scalable api?
Where is my scalable api?Where is my scalable api?
Where is my scalable api?Altoros
 
Gatling - Stress test tool
Gatling - Stress test toolGatling - Stress test tool
Gatling - Stress test toolKnoldus Inc.
 
AWS (Hadoop) Meetup 30.04.09
AWS (Hadoop) Meetup 30.04.09AWS (Hadoop) Meetup 30.04.09
AWS (Hadoop) Meetup 30.04.09Chris Purrington
 
Programming in Spark - Lessons Learned in OpenAire project
Programming in Spark - Lessons Learned in OpenAire projectProgramming in Spark - Lessons Learned in OpenAire project
Programming in Spark - Lessons Learned in OpenAire projectŁukasz Dumiszewski
 
Donald Ferguson - Old Programmers Can Learn New Tricks
Donald Ferguson - Old Programmers Can Learn New TricksDonald Ferguson - Old Programmers Can Learn New Tricks
Donald Ferguson - Old Programmers Can Learn New TricksServerlessConf
 
Oracle application testing suite (OATS)
Oracle application testing suite (OATS)Oracle application testing suite (OATS)
Oracle application testing suite (OATS)Koushik Arvapally
 
Apache® Spark™ 1.6 presented by Databricks co-founder Patrick Wendell
Apache® Spark™ 1.6 presented by Databricks co-founder Patrick WendellApache® Spark™ 1.6 presented by Databricks co-founder Patrick Wendell
Apache® Spark™ 1.6 presented by Databricks co-founder Patrick WendellDatabricks
 
Scala45 spray test
Scala45 spray testScala45 spray test
Scala45 spray testkopiczko
 
Google App Engine for Java
Google App Engine for JavaGoogle App Engine for Java
Google App Engine for JavaLars Vogel
 

Similaire à Nexthink Library - replacing a ruby on rails application with Scala and Spray (20)

Java 7 & 8
Java 7 & 8Java 7 & 8
Java 7 & 8
 
Extending Oracle E-Business Suite with Ruby on Rails
Extending Oracle E-Business Suite with Ruby on RailsExtending Oracle E-Business Suite with Ruby on Rails
Extending Oracle E-Business Suite with Ruby on Rails
 
Getting started with Apollo Client and GraphQL
Getting started with Apollo Client and GraphQLGetting started with Apollo Client and GraphQL
Getting started with Apollo Client and GraphQL
 
RSpec and Rails
RSpec and RailsRSpec and Rails
RSpec and Rails
 
Speedy TDD with Rails
Speedy TDD with RailsSpeedy TDD with Rails
Speedy TDD with Rails
 
Overhauling a database engine in 2 months
Overhauling a database engine in 2 monthsOverhauling a database engine in 2 months
Overhauling a database engine in 2 months
 
How easy (or hard) it is to monitor your graph ql service performance
How easy (or hard) it is to monitor your graph ql service performanceHow easy (or hard) it is to monitor your graph ql service performance
How easy (or hard) it is to monitor your graph ql service performance
 
Unit testing of spark applications
Unit testing of spark applicationsUnit testing of spark applications
Unit testing of spark applications
 
Java 8 Overview
Java 8 OverviewJava 8 Overview
Java 8 Overview
 
Expanding beyond SPL -- More language support in IBM Streams V4.1
Expanding beyond SPL -- More language support in IBM Streams V4.1Expanding beyond SPL -- More language support in IBM Streams V4.1
Expanding beyond SPL -- More language support in IBM Streams V4.1
 
Where is my scalable api?
Where is my scalable api?Where is my scalable api?
Where is my scalable api?
 
Gatling - Stress test tool
Gatling - Stress test toolGatling - Stress test tool
Gatling - Stress test tool
 
AWS (Hadoop) Meetup 30.04.09
AWS (Hadoop) Meetup 30.04.09AWS (Hadoop) Meetup 30.04.09
AWS (Hadoop) Meetup 30.04.09
 
Programming in Spark - Lessons Learned in OpenAire project
Programming in Spark - Lessons Learned in OpenAire projectProgramming in Spark - Lessons Learned in OpenAire project
Programming in Spark - Lessons Learned in OpenAire project
 
Donald Ferguson - Old Programmers Can Learn New Tricks
Donald Ferguson - Old Programmers Can Learn New TricksDonald Ferguson - Old Programmers Can Learn New Tricks
Donald Ferguson - Old Programmers Can Learn New Tricks
 
Spatial approximate string search Doc
Spatial approximate string search DocSpatial approximate string search Doc
Spatial approximate string search Doc
 
Oracle application testing suite (OATS)
Oracle application testing suite (OATS)Oracle application testing suite (OATS)
Oracle application testing suite (OATS)
 
Apache® Spark™ 1.6 presented by Databricks co-founder Patrick Wendell
Apache® Spark™ 1.6 presented by Databricks co-founder Patrick WendellApache® Spark™ 1.6 presented by Databricks co-founder Patrick Wendell
Apache® Spark™ 1.6 presented by Databricks co-founder Patrick Wendell
 
Scala45 spray test
Scala45 spray testScala45 spray test
Scala45 spray test
 
Google App Engine for Java
Google App Engine for JavaGoogle App Engine for Java
Google App Engine for Java
 

Dernier

Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software DevelopersVinodh Ram
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...soniya singh
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...OnePlan Solutions
 
Active Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdfActive Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdfCionsystems
 
why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfjoe51371421
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...OnePlan Solutions
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsAndolasoft Inc
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsArshad QA
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AIABDERRAOUF MEHENNI
 
DNT_Corporate presentation know about us
DNT_Corporate presentation know about usDNT_Corporate presentation know about us
DNT_Corporate presentation know about usDynamic Netsoft
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...MyIntelliSource, Inc.
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideChristina Lin
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantAxelRicardoTrocheRiq
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfkalichargn70th171
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfkalichargn70th171
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...MyIntelliSource, Inc.
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...stazi3110
 

Dernier (20)

Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software Developers
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
 
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS LiveVip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...
 
Active Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdfActive Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdf
 
why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdf
 
Exploring iOS App Development: Simplifying the Process
Exploring iOS App Development: Simplifying the ProcessExploring iOS App Development: Simplifying the Process
Exploring iOS App Development: Simplifying the Process
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.js
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
 
DNT_Corporate presentation know about us
DNT_Corporate presentation know about usDNT_Corporate presentation know about us
DNT_Corporate presentation know about us
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
 
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service Consultant
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
 

Nexthink Library - replacing a ruby on rails application with Scala and Spray

  • 1. Nexthink Library in Scala Implementation & Techniques Replacing a Ruby on Rails Application with Scala / Spray
  • 2. Matthew Farwell Senior Developer @ Nexthink in Lausanne Java / Scala / JVM Project lead on Scalastyle, the style checker for Scala Contributor to other open source projects, JUnit Co-author of “sbt in Action” with Josh Suereth
  • 5. Project Goals To rewrite the existing Ruby on Rails Library To make it more ‘mainstream’ in the company Increase the truck number Have adequate performance for the future. Assess technologies: – Spray for web container, async, non-blocking – Slick for database access (instead of Hibernate) – Gatling for performance tests – Angular JS for front end
  • 6. Existing solution Split into two parts: API used by Finder and Portal, both GET and POST 5 different types of request Administration section, for updating content Requirements – For the API, it must do exactly the same as the legacy. – The admin section can be improved if we want
  • 7. Approach A single rest server which serves both the API and the admin screens (Spray) The admin screens use Angular JS, which themselves use the REST APIs Server is stateless, therefore no sessions, etc. Text search uses Lucene
  • 8. Spray Spray is a DSL to describe a REST API along with the actions. It is a mixture of directives and actions: path("1" / "ping") { get { respondWithMediaType(`application/json`) { complete { Ping(Settings.config.hostname, databaseOk()) } } } } implicit val pingFormat = jsonFormat2(Ping)
  • 9. Spray It makes things easy to do asynchronously and non- blocking: complete { future { val u = entityService.update(id, obj, user) future { LibraryApi.refreshCache } u } } complete { pipeline(Get("http://google.com")) }
  • 11. API Testing We can test the new library by comparing directly with the legacy library. So how do we generate the test cases? We can: use the access log for the legacy library to get a typical set of requests generate test cases using Scalacheck
  • 12. Scalacheck Scalacheck allows you to generate data for tests It can generate random structured data It then calls the Method Under Test and compares the result using properties It can then ‘reduce’ the use case to the smallest size which fails In our case, we only use the generation methods
  • 13. Scalacheck example This generates one type of request: val gen: Gen[Parameters] = for { elementTypes <- Gen.oneOf("alert", "investigation") tag <- Gen.containerOf[List, String]( Gen.oneOf("", "cloud", "security")) version <- Gen.oneOf("", "3.1", "4", "5") } yield Parameters("categories", 100, tag, elementTypes, version, license) We run this 5000 times per type of request for our basic tests. Scalacheck is very good for exploring an API and finding edge cases.
  • 15. Proxy/Comparison The new library proxies the legacy. When we call the legacy (non-blocking), we return those results. When we return the results, we asynchronously compare the results with the new library. We can put this into production without fear complete { val f = pipeline(Get(legacyUrl(params))) f onComplete { result => compare(result, localApi(params)) } f }
  • 16. Proxy/Comparison If there is a comparison failure, we store the parameters that failed, which we can access from the FE. We record all of the parameters from a GET or a POST. We can also replay a failure This approach means that we have to share the database – so we didn't change it at all. We had different comparison strategies depending upon the type of API call.
  • 17. Some numbers Legacy RoR ~3400 lines (.rb, .erb, .xml.builder) New: ~3400 lines Scala (500 lines comparison/proxy) ~1000 lines JavaScript (Angular JS) ~650 lines HTML Spring app (similar) backend with DB: ~9000 lines Java Frontend (GWT): ~16000 lines Java
  • 18. Performance Tests – Gatling Define a scenario: val scn = scenario("basic usage") .group("search") { repeat(100) { exec(http("google").get("http://google.com")) .pause(0 milliseconds, 2 milliseconds) .exec(http("yahoo").get("http://yahoo.com")) } }
  • 19. Performance Tests – Gatling Execute it: setUp(scn.inject(ramp(10 users) over (10 seconds))) .protocols(httpConf) .assertions( global.successfulRequests.percent.is(100), details("search"/"google").responseTime.max.lessThan(100), details("search"/"yahoo").responseTime.max.lessThan(100)) Gatling
  • 20. Performance – RoR baseline 5 Users, 5 times, 10 requests == 250 requests Total time: 227 seconds, req/s = 1 Caveats: unstable setup, production (single request) was faster x 10 Mean Max search 7600 8900 featured 2500 3200 copy 6300 7000
  • 21. Performance – New 5 Users, 5 times, 10 requests == 250 requests Total time: 5 seconds, req/s = 50 Mean Max search 11 30 featured 5 10 copy 0 0
  • 22. Performance – New 100 Users, 100 times, 10 requests == 100,000 requests Total time: 28 seconds, req/s = 3571 3571 req/s == 300,000,000 / day Mean Max search 33 660 featured 24 500 copy 22 460
  • 23. Performance – New 1000 Users, 100 times, 10 requests == 1,000,000 requests Total time: 280 seconds, req/s = 3564 Required: 150-160k / day We can support 1 day’s traffic in < 1 minute. We have room for expansion :-) Mean Max search 383 15400 featured 259 23510 copy 260 33310
  • 24. Some interesting numbers Number of failures during performance tests: 0 This means that the system is very stable. The throughput for 100 concurrent users (3571 req/s) is about the same as for 1000 concurrent users (3564 req/s), but each request takes longer when there are 1000 concurrent users. This is due to back pressure.
  • 25. Production Production: April 2014 Proxies were in place 6-8 weeks Bugs found: 1 - incorrect version (attribute value) returned 2 – Finder was using empty url as a ping 3 – incorrect data returned (cause: data in database) 4 – encoding problem
  • 26. Conclusion Scala (language and tools) compilation slow, tooling great (sbt & worksheet) Spray easy to use, simple to extend, no real ‘magic’ Scalacheck very good for exploring an API, and finding edge cases, good for data oriented testing Slick – easy to use, we were only doing simple things, but very similar to working with direct SQL.
  • 27. Conclusion Angular JS Great. Better than some of the other solutions we've had. Async / non-blocking Fairly easy to manage in Scala, harder in Java. Harder when dealing with databases and non-web services. Gatling Great. Simple and easy. Miles better than the alternatives (JMeter for example)
  • 28. Questions? Twitter: @matthewfarwell Scalastyle: @scalastyle http://www.scalastyle.org Sbt in Action: https://www.manning.com/books/sbt-in-action Nexthink are hiring! http://www.nexthink.com

Notes de l'éditeur

  1. &amp;lt;number&amp;gt;
  2. &amp;lt;number&amp;gt;
  3. &amp;lt;number&amp;gt;
  4. &amp;lt;number&amp;gt;
  5. &amp;lt;number&amp;gt;
  6. &amp;lt;number&amp;gt;
  7. &amp;lt;number&amp;gt;
  8. complete can return HttpResponse, a String/Byte Array, or something which can be translated into JSON. It can also return a future of all of these things. Authentication is just another directive. &amp;lt;number&amp;gt;
  9. complete can return HttpResponse, a String/Byte Array, or something which can be translated into JSON. It can also return a future of all of these things. Authentication is just another directive. &amp;lt;number&amp;gt;
  10. &amp;lt;number&amp;gt;
  11. &amp;lt;number&amp;gt;
  12. &amp;lt;number&amp;gt;
  13. containerOf, one of, mention frequency &amp;lt;number&amp;gt;
  14. Diagram here please Pipeline non-blocking, when this completes we return the response from the legacy library and then fire off a comparison. &amp;lt;number&amp;gt;
  15. Diagram here please Pipeline non-blocking, when this completes we return the response from the legacy library and then fire off a comparison. &amp;lt;number&amp;gt;
  16. Diagram here please Pipeline non-blocking, when this completes we return the response from the legacy library and then fire off a comparison. &amp;lt;number&amp;gt;
  17. RoR does email sending, public front end, wc -l &amp;lt;number&amp;gt;
  18. &amp;lt;number&amp;gt;
  19. &amp;lt;number&amp;gt;
  20. &amp;lt;number&amp;gt;
  21. &amp;lt;number&amp;gt;
  22. Calculate 3571 / 108 ~= 33 &amp;lt;number&amp;gt;
  23. &amp;lt;number&amp;gt;
  24. 145k / day == last_elements &amp;lt;number&amp;gt;
  25. 145k / day == last_elements &amp;lt;number&amp;gt;
  26. &amp;lt;number&amp;gt;
  27. &amp;lt;number&amp;gt;
  28. &amp;lt;number&amp;gt;