Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Elixir

Naoya Ito
October 09, 2015

 Elixir

Kaizen Platform, Inc の社内勉強会での資料です。基本的には以前発表した資料の切り貼りです

Naoya Ito

October 09, 2015
Tweet

More Decks by Naoya Ito

Other Decks in Technology

Transcript

  1. &MJYJS •  &SMBOH7.ͷ্Ͱಈ͘ݴޠ –  &SMBOH7.ͷڧΈ ฒߦॲཧੑೳɺ଱ো֐ੑ Λͦͷ··ʹɺγϯλο ΫεΛೃછΈ΍͘͢ •  KPTFWBMJN&SMBOHͰݟͨ͜ͱ͸ΈΜͳؾʹೖ͚ͬͨͲɺݟͳ͔ͬͨ͜ͱ͸

    ΈΜͳݏ͍ –  &SMBOHͱ૬ޓޓ׵ –  051΋΋ͪΖΜ͋ΔΑ •  Ϟμϯͳύοέʔδ؅ཧγεςϜɺ-B[ZίϨΫγϣϯ 4USFBN ɺ ϓϩτίϧͳͲͷ௥Ճཁૉ •  ৄ͘͠͸ –  IUUQTTQFBLFSEFDLDPNOBPZBFMJYJSHPTIBPKJF
  2. &MJYJS ͳͲ ΛֶͿͱྑ͍ཧ༝ •  ݴޠτϨϯυͷҠΓมΘΓ –  4DBMBɺ&MJYJSɺ$MPKVSFɺ(Pɺ3VTU  •  ΑΓ4IBSFE/PUIJOH΁

    –  Ϋϥ΢υωΠςΟϒŋŋŋԣʹεέʔϧ –  ϞμϯͳฒߦɾฒྻΞϓϩʔν –  *NNVUBCMFͳσʔλܕ –  ແݶσʔλ 8FC͔Βྲྀೖ͚ͭͮ͠ΔσʔλͳͲ ͷந৅ తѻ͍ –  㱺ؔ਺ܕݴޠ
  3. ؔ਺ܕͷτϨϯυ •  ৽͍͠ݴޠʹ͸େͳΓখͳΓؔ਺ܕͷΤοηϯ ε –  4DBMBɺ&MJYJSɺ$MPKVSFɺ3VTUɺ4XJGU  •  طଘͷݴޠʹ΋Өڹ – 

    +BWBͷ0QUJPOBMܕ •  จ຺Λ࣋ͬͨ஋ Ϟφυ  –  &4 #BCFM  •  ͳΜ͔#BCFMʹ຤ඌݺͼग़͠࠷దԽೖͬͨΒ͍͠
  4. ϞμϯͳϥϯλΠϜ •  $$ ΍-".1ݴޠʹ͸ͳ͔ͬͨ৽͍͠ػೳΛϥϯλ ΠϜ͕͍࣋ͬͯΔ –  ྫϝϞϦϞσϧ •  &SMBOH&MJYJSͷ1FS1SPDFTT($ • 

    3VTUͷΦʔφʔγοϓϞσϧ –  ྫฒߦɾฒྻॲཧ •  "DUPS •  $IBOOFM •  45. –  ྫ଱ো֐Ϟσϧ •  -FUJUDSBTI
  5. Α͏͢Δʹ •  ݴޠͷύϥμΠϜ͕มΘΖ͏ͱͯ͠Δ –  ύϥμΠϜ͕มΘΔͱ͍͏ΑΓผͷύϥμΠϜͷݴޠʹτϨϯυ ͕ҠΓͭͭ͋Δ •  ͦͷลͷݴޠʹೃછΜͰ͓͘ͱ૯߹తͳֶशίετΛԼ ͛ΒΕΔ – 

    +4΍3VCZʹೖΖ͏ͱͯ͠Δมߋͷഎܠ –  ৽͍͠ϛυϧ΢ΣΞɺϑϨʔϜϫʔΫ΍ϥΠϒϥϦͷΠϯλ ϑΣʔε –  ʮϦΞΫςΟϒʯ΍ʮετϦʔϜʯΈ͍ͨͳύϥμΠϜ ͳͷͰʮ&MJYJSΛֶ΂ʯͱ͍ ͏ΑΓͦͷลͷ৽͍͠ͷԿ͔ ΍ͬͱ͘ͱ͍͍Α͍ͬͯ͏࿩
  6. 1SPT$POT •  1SPT –  ҆શ •  ϦΫΤετ͝ͱʹϝϞϦۭؒ෼཭㱺Ϋϥογϡͯ͠΋ ଞʹӨڹ͠ͳ͍ –  ϓϩάϥϛϯάϞσϧ͕୯७

    ಉظͰ0,  –  ϚϧνίΞ •  $POT –  εέʔϥϏϦςΟʹ೉ •  ϝϞϦେ㱺࠷େϓϩηε਺ಉ࣌ฒߦ਺্ݶ •  04ϓϩηεεϨουͷίϯςΩετεΠον
  7. ࣌ؒ A B A C D B ・・・ select() /

    epoll() ίϯςΩετ εΠον ΠϕϯτۦಈϞσϧʹΑΔฒߦॲཧ ྫ&WFOU.BDIJOF /PEFKT 
  8. 1SPT$POT •  1SPT –  εέʔϥϏϦςΟ ߴ͍ฒߦॲཧੑೳ  •  ϝϞϦϑοτϓϦϯτখ͍͞ • 

    ಉ࣌઀ଓ਺͕૿͑ͯ΋εέʔϧ •  $POT –  ଱ো֐ੑʹ೉ •  མͪΔͱ͖͸શ෦མͪΔ •  ϝϞϦϦʔΫ͜Θ͍ –  ϓϩάϥϛϯάϞσϧ͕΍΍ෳࡶ˞/PEFKTͩͱͦΕ΄ͲͰ΋ͳ͍  –  ϚϧνίΞ$16Λ࢖͍ͮΒ͍
  9. &SMBOHͷ࣮ߦ؀ڥ •  #&". &SMBOH7.  –  ܰྔϓϩηεŋŋŋ࣮ߦίϯςΩετ •  খ͍͞ϫʔυɺىಈʹdϚΠΫϩඵ – 

    ฒߦॲཧੑೳ͕ߴ͍ •  7.͕ܰྔϓϩηεΛεέδϡʔϦϯά –  7.εϨουຖʹϥϯΩϡʔ –  ཪଆͰ͸ඇಉظεϨουϓʔϧ ref: h+p://www.erlang-factory.com/upload/presenta=ons/708/HitchhikersTouroEheBEAM.pdf
  10. &SMBOHͰͷ ωοτϫʔΫαʔόʔ •  ϦΫΤετʹܰྔϓϩηε –  ҆શ •  ܰྔϓϩηεŋŋŋಠཱ࣮ͨ͠ߦίϯςΩετ •  4IBSFE/PUIJOHŋŋŋ͋Δϓϩηε͕Ϋϥογϡͯ͠΋໰୊

    ͳ͍ –  ߴ͍ฒߦॲཧੑೳ •  ܰྔŋŋŋϝϞϦϑοτϓϦϯτখ͍͞ •  Ϣʔβʔϥϯυ04ͷίϯςΩετεΠονͳ͠
  11. &SMBOHͷϝϞϦϞσϧ •  QFS1SPDFTT($ –  ϓϩηεຖʹ($ •  άϩʔόϧ($ͩͱશମʹӨڹ͢Δ •  ϓϩηε෼཭ – 

    4IBSFE/PUIJOH –  ϓϩηε)FBQ •  ($͸ܰྔϓϩηεຖʹ૸ΒͤɺཁΒͳ͘ͳͬͨΒഇغ ؆୯Ͱޮ཰ ͕Α͍  ҆ఆͨ͠Ԡ౴ੑೳ ߴ͍଱ো֐ੑ
  12. &MJYJS •  &SMBOH7.ͷ্Ͱಈ͘ݴޠ –  &SMBOH7.ͷڧΈ ฒߦॲཧੑೳɺ଱ো֐ੑ Λͦͷ··ʹɺγϯλο ΫεΛೃછΈ΍͘͢ •  KPTFWBMJN&SMBOHͰݟͨ͜ͱ͸ΈΜͳؾʹೖ͚ͬͨͲɺݟͳ͔ͬͨ͜ͱ͸

    ΈΜͳݏ͍ –  &SMBOHͱ૬ޓޓ׵ –  051΋΋ͪΖΜ͋ΔΑ •  Ϟμϯͳύοέʔδ؅ཧγεςϜɺ-B[ZίϨΫγϣϯ 4USFBN ɺ ϓϩτίϧͳͲͷ௥Ճཁૉ •  ৄ͘͠͸ –  IUUQTTQFBLFSEFDLDPNOBPZBFMJYJSHPTIBPKJF
  13. ϕϯνϚʔΫ ref: h+p://www.li+lelines.com/blog/2014/07/08/elixir-vs-ruby-showdown-phoenix-vs-rails/ $ ./wrk -t12 -c800 -d180S --timeout 2000

    "http://tranquil-brushlands-6459.herokuapp.com/showdown" Running 3m test @ http://tranquil-brushlands-6459.herokuapp.com/showdown 12 threads and 800 connections Thread Stats Avg Stdev Max +/- Stdev Latency 318.52ms 139.92ms 1.39s 82.03% Req/Sec 224.42 57.23 368.00 68.50% 484444 requests in 3.00m, 0.99GB read Socket errors: connect 0, read 9, write 0, timeout 0 Requests/sec: 2691.03 Transfer/sec: 5.65MB $ ./wrk -t12 -c800 -d180S --timeout 2000 "http://dry-ocean-9525.herokuapp.com/showdown" Running 3m test @ http://dry-ocean-9525.herokuapp.com/showdown 12 threads and 800 connections Thread Stats Avg Stdev Max +/- Stdev Latency 3.07s 2.06s 8.36s 70.39% Req/Sec 24.65 9.97 63.00 67.10% 54256 requests in 3.00m, 122.50MB read Socket errors: connect 0, read 1, write 0, timeout 0 Requests/sec: 301.36 Transfer/sec: 696.77KB Phoenix Rails w/ Puma ॾ৚݅͋ΔͷͰߟ࡯͸ࣗݾ੹೚Ͱɻ 1IPFOJY͕ൺֱͯ͠଎͍ͷ͸ؒҧ ͍ͳͦ͞͏ 
  14. ͳ͍΋ͷ •  Ͱ͸ ͳ͍ –  ΦϒδΣΫτࢦ޲ –  ੩తܕ෇͚ –  ७ਮؔ਺ܕ

    ෭࡞༻͋Γ  –  ෦෼ద༻ΧϦʔԽ –  0QUJPOBMܕ .BZCF  •  ͋ΔΑ –  Ϧετ಺แදه –  ஗ԆධՁɺແݶϦετ ˞ݴޠશମͰ͸ͳ͍  –  Ϟφυ͸܅ͨͪͷ৺ͷதʹ
  15. ෆมͳσʔλܕ •  σʔλܕ͸ෆม –  4USJOH -JTU 5VQMF .BQ )BTI%JDU )BTI4FU

    •  ཁ͢Δʹഁյతૢ࡞͕ෆՄೳ͚ͬͯͩ •  dict2 = Dict.put(dict, :foo, 3) –  dict ͸ෆมɺߋ৽͞Εͨ dict2
  16. GPS XIJMF͕ͳ͍ •  ࠶ؼΛ࢖͏͔ ຤ඌݺͼग़͠࠷దԽ  •  ͞΋ͳ͘͹ϧʔΫɺ&OVNΛ࢖͑ iex> [1,2,3]

    |> Enum.each fn(x) -> IO.puts(x) end 1 2 3 :ok iex> [1,2,3] |> Enum.reduce(0, fn(x, acc) -> x + acc end) 6
  17. Ϧετ಺แදه •  )BTLFMM౳Ͱ͓ͳ͡Έͷ – [x | x <- xs, x <

    p] •  &MJYJSͰ͸ – for x <- xs, x < p, do: x ਖ਼௚͜Εʹؔͯ͠͸ &SMBOHͦͷ··Ͱྑ͔ͬ ͨͷͰ͸ŋŋŋ4DBMBΠϯε ύΠΞ͔ͳ
  18. ΞΫλʔϞσϧ •  ϓϩηεؒ௨৴͸ϝοηʔδύογϯά –  ϓϩηεͷதʹʮϝʔϧϘοΫεʯ •  ͦ͜ʹϝοηʔδΛૹΔ TFOE  • 

    ϝοηʔδʹ͸೚ҙͷ஋Λఴ෇Մ –  ϓϩηε͸ͦΕΛड৴଴ͪ SFDFJWF  –  ஋͸ඞͣίϐʔ͞ΕΔ ڞ༗͞Εͳ͍  •  σʔλΛڞ༗͠ͳ͍㱺ϩοΫ͕͍Βͳ͍
  19. &MJYJSೖ໳ιʔε ೔ຊޠ  •  8FC %#13&44WPM –  IUUQHJIZPKQNBHB[JOFXEQSFTTBSDIJWFWPM  • 

    +PF@OPI͞ΜͷεϥΠυू –  IUUQXXXTMJEFTIBSFOFU+PF@OPIQSFTFOUBUJPOT •  (FUUJOH4UBSUFEͷ຋༁ –  IUUQFMJYJSKBTFOBOFUXPSLTHFUUJOH@TUBSUFEIUNM •  2JJUBr&MJYJS –  IUUQTRJJUBDPNUBHTFMJYJS
  20. ྑ͍͜ͱ͹͔Γݴ͍·͕ͨ͠ŋŋŋ •  ฒߦੑೳ͕ߴ͍ɺԠ౴ੑೳ͕ྑ͍ͱ͸ݴ͕ͬͨʮܭࢉ͕ ଎͍ʯͱ͸ݴͬͯͳ͍ –  1IPFOJYελοΫ͸3BJMTΑΓ͸଎͍ɺ͚Ͳ΋ –  ಈతܕ෇͚ݴޠͰ͢͠ –  ˞ҰԠ)J1&ʹ͢Δͱ଎͘͸ͳΔ΋Α͏

    •  ؔ਺ܕݴޠͱͯ͠͸ͦ͜·ͰߴػೳͰ͸ͳ͍ •  ݸਓతͳ࿩ େن໛ӡ༻ͯ͠ͳ͍ͷͰ$POTΛޠΔʹ஌ ݟ଍Γͳ͍ •  &MJYJSྲྀߦΔ͔͸·ͩະ஌਺ –  ϓϩμΫγϣϯ౤ೖࣄྫ͸·ͩ͜Ε͔Β