SlideShare ist ein Scribd-Unternehmen logo
1 von 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

Weitere ähnliche Inhalte

Was ist angesagt?

Was ist angesagt? (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
 

Andere mochten auch

Manufacturing pov jeff green 2016 v2
Manufacturing pov jeff green 2016 v2Manufacturing pov jeff green 2016 v2
Manufacturing pov jeff green 2016 v2
Jeff Green
 
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
 

Andere mochten auch (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
 

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

Java 7 & 8
Java 7 & 8Java 7 & 8
Java 7 & 8
Ken Coenen
 

Ähnlich wie 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
 

Kürzlich hochgeladen

CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is inside
shinachiaurasa2
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
masabamasaba
 

Kürzlich hochgeladen (20)

CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
%+27788225528 love spells in Vancouver Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Vancouver Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Vancouver Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Vancouver Psychic Readings, Attraction spells,Br...
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is inside
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
 
Generic or specific? Making sensible software design decisions
Generic or specific? Making sensible software design decisionsGeneric or specific? Making sensible software design decisions
Generic or specific? Making sensible software design decisions
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students
 
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdfPayment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
Exploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdfExploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdf
 
Define the academic and professional writing..pdf
Define the academic and professional writing..pdfDefine the academic and professional writing..pdf
Define the academic and professional writing..pdf
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
 
Announcing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK SoftwareAnnouncing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK Software
 
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
 
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...
 

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

Hinweis der Redaktion

  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;