Successfully reported this slideshow.
Your SlideShare is downloading. ×

Lightweight APIs in mRuby (Михаил Бортник)

Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Upcoming SlideShare
Lightweight APIs in mRuby
Lightweight APIs in mRuby
Loading in …3
×

Check these out next

1 of 69 Ad

More Related Content

Viewers also liked (20)

Similar to Lightweight APIs in mRuby (Михаил Бортник) (20)

Advertisement

More from Fwdays (20)

Recently uploaded (20)

Advertisement

Lightweight APIs in mRuby (Михаил Бортник)

  1. 1. Lightweight APIs in mRuby 1 / 68
  2. 2. Who am I 2 / 68
  3. 3. Who am I Name's Mikhail Bortnyk 3 / 68
  4. 4. Who am I Name's Mikhail Bortnyk Ruby developer and team leader in R&R Music Ukraine 4 / 68
  5. 5. Who am I Name's Mikhail Bortnyk Ruby developer and team leader in R&R Music Ukraine Co-creator of Kottans school 5 / 68
  6. 6. Who am I Name's Mikhail Bortnyk Ruby developer and team leader in R&R Music Ukraine Co-creator of Kottans school Geek, polyglot, software development addict 6 / 68
  7. 7. Who am I Name's Mikhail Bortnyk Ruby developer and team leader in R&R Music Ukraine Co-creator of Kottans school Geek, polyglot, software development addict github: @vessi 7 / 68
  8. 8. Who am I Name's Mikhail Bortnyk Ruby developer and team leader in R&R Music Ukraine Co-creator of Kottans school Geek, polyglot, software development addict github: @vessi twitter: @mikhailbortnyk 8 / 68
  9. 9. What is mRuby 9 / 68
  10. 10. What is mRuby mRuby is lightweight implementation of Ruby complying (partially) to ISO/IEC 30170:2012 10 / 68
  11. 11. What is mRuby mRuby is lightweight implementation of Ruby complying (partially) to ISO/IEC 30170:2012 can be linked and embedded into your application 11 / 68
  12. 12. What is mRuby mRuby is lightweight implementation of Ruby complying (partially) to ISO/IEC 30170:2012 can be linked and embedded into your application can compile your software into bytecode 12 / 68
  13. 13. What is mRuby mRuby is lightweight implementation of Ruby complying (partially) to ISO/IEC 30170:2012 can be linked and embedded into your application can compile your software into bytecode can generate C code for embedding bytecode 13 / 68
  14. 14. What is mRuby mRuby is lightweight implementation of Ruby complying (partially) to ISO/IEC 30170:2012 can be linked and embedded into your application can compile your software into bytecode can generate C code for embedding bytecode author: Yukihiro 'matz' Matsumoto 14 / 68
  15. 15. What is mRuby mRuby is lightweight implementation of Ruby complying (partially) to ISO/IEC 30170:2012 can be linked and embedded into your application can compile your software into bytecode can generate C code for embedding bytecode author: Yukihiro 'matz' Matsumoto github: github://mruby/mruby 15 / 68
  16. 16. What is mRuby mRuby is lightweight implementation of Ruby complying (partially) to ISO/IEC 30170:2012 can be linked and embedded into your application can compile your software into bytecode can generate C code for embedding bytecode author: Yukihiro 'matz' Matsumoto github: github://mruby/mruby latest version: 1.1.0 16 / 68
  17. 17. Typical Rails project 17 / 68
  18. 18. Typical Rails project (I am so sorry for it, mom!) 18 / 68
  19. 19. Typical Rails project it's based on Rack 19 / 68
  20. 20. Typical Rails project it's based on Rack it contains a lot of business processes 20 / 68
  21. 21. Typical Rails project it's based on Rack it contains a lot of business processes it responds to many routes 21 / 68
  22. 22. Typical Rails project it's based on Rack it contains a lot of business processes it responds to many routes often too heavy to serve tons of lightweight requests without scaling 22 / 68
  23. 23. Typical Rails project it's based on Rack it contains a lot of business processes it responds to many routes often too heavy to serve tons of lightweight requests without scaling So, what is the solution? 23 / 68
  24. 24. Solutions 24 / 68
  25. 25. Solutions You have a problem and decide to use threads. Two now problems have you. 25 / 68
  26. 26. Solutions You have a problem and decide to use threads. Two now problems have you. You have a problem and decide to use functional languages. Now your problems are immutable. 26 / 68
  27. 27. Solutions You have a problem and decide to use threads. Two now problems have you. You have a problem and decide to use functional languages. Now your problems are immutable. You have a problem and decide to use Java. Now you have ProblemsFactory. 27 / 68
  28. 28. Solutions You have a problem and decide to use threads. Two now problems have you. You have a problem and decide to use functional languages. Now your problems are immutable. You have a problem and decide to use Java. Now you have ProblemsFactory. You have a problem and decide... 28 / 68
  29. 29. Kill it with fire! 29 / 68
  30. 30. Kill it with fire! Microservices 30 / 68
  31. 31. Microservices 31 / 68
  32. 32. Microservices 32 / 68
  33. 33. Microservices The idea is to split big project in bunch of independent lightweight services. 33 / 68
  34. 34. Microservices The idea is to split big project in bunch of independent lightweight services. Requirements: 34 / 68
  35. 35. Microservices The idea is to split big project in bunch of independent lightweight services. Requirements: be fast 35 / 68
  36. 36. Microservices The idea is to split big project in bunch of independent lightweight services. Requirements: be fast be lightweight 36 / 68
  37. 37. Microservices The idea is to split big project in bunch of independent lightweight services. Requirements: be fast be lightweight be stable 37 / 68
  38. 38. Microservices The idea is to split big project in bunch of independent lightweight services. Requirements: be fast be lightweight be stable don't switch technology stack aggresively 38 / 68
  39. 39. Microservices The idea is to split big project in bunch of independent lightweight services. Requirements: be fast be lightweight be stable don't switch technology stack aggresively So, I decided to use mRuby. What do we have for serving web here? 39 / 68
  40. 40. Microservices The idea is to split big project in bunch of independent lightweight services. Requirements: be fast be lightweight be stable don't switch technology stack aggresively So, I decided to use mRuby. What do we have for serving web here? mod_mruby. Apache module that executes mRuby code inside Apache process. 40 / 68
  41. 41. Microservices The idea is to split big project in bunch of independent lightweight services. Requirements: be fast be lightweight be stable don't switch technology stack aggresively So, I decided to use mRuby. What do we have for serving web here? mod_mruby. Apache module that executes mRuby code inside Apache process. ngx_mruby. Perfectly the same but with Nginx flavour. 41 / 68
  42. 42. Little demonstration Microservice without any service 42 / 68
  43. 43. Little demonstration Used software: nginx (ALL) docker (ALL) docker-compose (ALL) mongodb (ALL) ab (ALL) unicorn gem (rack) rack gem (rack) rack-routing gem (rack) mongo gem (rack) ngx_mruby (mRuby) mruby-mongo (mRuby) 43 / 68
  44. 44. Rack execution $> cd testlab/rack $> docker-compose up $> ab -n 10000 -c 100 http://192.168.0.100:10080/api/contacts # and kill docker-compose with ^C 44 / 68
  45. 45. Rack stats (page 1) Document Path: /api/contacts Document Length: 537 bytes Concurrency Level: 100 Time taken for tests: 7.897 seconds Complete requests: 10000 Failed requests: 4399 (Connect: 0, Receive: 0, Length: 4399, Exceptions: 0) Non-2xx responses: 5601 Total transferred: 5080859 bytes HTML transferred: 3434440 bytes Requests per second: 1266.27 [#/sec] (mean) Time per request: 78.972 [ms] (mean) Time per request: 0.790 [ms] (mean, across all concurrent requests) Transfer rate: 628.29 [Kbytes/sec] received 45 / 68
  46. 46. Rack stats (page 2) Connection Times (ms) min mean[+/-sd] median max Connect: 0 4 4.1 2 34 Processing: 1 74 72.1 23 423 Waiting: 1 74 72.0 22 423 Total: 2 78 72.2 27 426 Percentage of the requests served within a certain time (ms) 50% 27 66% 135 75% 147 80% 154 90% 174 95% 192 98% 216 99% 232 100% 426 (longest request) 46 / 68
  47. 47. mRuby execution $> cd testlab/rack $> docker-compose up $> ab -n 10000 -c 100 http://192.168.0.100:10080/api/contacts # and kill docker-compose with ^C 47 / 68
  48. 48. mRuby stats (page 1) Document Path: /api/contacts Document Length: 98 bytes Concurrency Level: 100 Time taken for tests: 6.721 seconds Complete requests: 10000 Failed requests: 0 Total transferred: 2140000 bytes HTML transferred: 980000 bytes Requests per second: 1487.83 [#/sec] (mean) Time per request: 67.212 [ms] (mean) Time per request: 0.672 [ms] (mean, across all concurrent requests) Transfer rate: 310.93 [Kbytes/sec] received 48 / 68
  49. 49. mRuby stats (page 2) Connection Times (ms) min mean[+/-sd] median max Connect: 0 3 5.9 0 29 Processing: 5 64 27.5 68 132 Waiting: 5 64 27.6 68 131 Total: 14 67 24.4 69 132 Percentage of the requests served within a certain time (ms) 50% 69 66% 78 75% 83 80% 88 90% 102 95% 106 98% 112 99% 120 100% 132 (longest request) 49 / 68
  50. 50. Problems 50 / 68
  51. 51. Problems Everything has its price. ngx_mruby and Nginx and mRuby are not exceptions. 51 / 68
  52. 52. Problems Everything has its price. ngx_mruby and Nginx and mRuby are not exceptions. you have to recompile mRuby each time you add some dependency 52 / 68
  53. 53. Problems Everything has its price. ngx_mruby and Nginx and mRuby are not exceptions. you have to recompile mRuby each time you add some dependency oftenly gems are written in pure C 53 / 68
  54. 54. Problems Everything has its price. ngx_mruby and Nginx and mRuby are not exceptions. you have to recompile mRuby each time you add some dependency oftenly gems are written in pure C mRuby has no require keyword, so you code will not be so DRY as you want 54 / 68
  55. 55. Problems Everything has its price. ngx_mruby and Nginx and mRuby are not exceptions. you have to recompile mRuby each time you add some dependency oftenly gems are written in pure C mRuby has no require keyword, so you code will not be so DRY as you want still not so fast as pure C implementation :( 55 / 68
  56. 56. Problems Everything has its price. ngx_mruby and Nginx and mRuby are not exceptions. you have to recompile mRuby each time you add some dependency oftenly gems are written in pure C mRuby has no require keyword, so you code will not be so DRY as you want WRONG! still not so fast as pure C implementation :( 56 / 68
  57. 57. mruby-require to the rescue! 57 / 68
  58. 58. mruby-require to the rescue! mruby-require allows you both to don't hold some gems in your mRuby virtual machine and to require your own code. 58 / 68
  59. 59. mruby-require to the rescue! mruby-require allows you both to don't hold some gems in your mRuby virtual machine and to require your own code. located at: github://mattn/mruby-require 59 / 68
  60. 60. mruby-require to the rescue! mruby-require allows you both to don't hold some gems in your mRuby virtual machine and to require your own code. located at: github://mattn/mruby-require gems that are located in build_config.rb before mruby-require - are included in mRuby VM, after - are not 60 / 68
  61. 61. mruby-require to the rescue! mruby-require allows you both to don't hold some gems in your mRuby virtual machine and to require your own code. located at: github://mattn/mruby-require gems that are located in build_config.rb before mruby-require - are included in mRuby VM, after - are not requirements are loaded at each execution 61 / 68
  62. 62. Miss Rack? 62 / 68
  63. 63. Miss Rack? mruby-hibari is the abstraction that is pretty similiar to well-known Rack interface. But just faster a lot. 63 / 68
  64. 64. Miss Rack? mruby-hibari is the abstraction that is pretty similiar to well-known Rack interface. But just faster a lot. Find it at github://kentaro/mruby-hibari 64 / 68
  65. 65. Seeking for opensource developers! I am looking for support to continue development of mruby-mongo. Any help will be appreciated. 65 / 68
  66. 66. Still actual :( 66 / 68
  67. 67. Questions? 67 / 68
  68. 68. Thank you! 68 / 68

×