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

Erlang/OTP初心者がシステムを構築するまで - 第62回 SEA関西プロセス分科会

Erlang/OTP初心者がシステムを構築するまで - 第62回 SEA関西プロセス分科会

Ryuichi Maeno

February 14, 2015
Tweet

Other Decks in Programming

Transcript

  1. ੑೳධՁ  ಉ࣌઀ଓ w $,8FCTPDLFU5FTU w IUUQTHJUIVCDPNFSJDNPSJU[XTEFNPCMPCSFTVMUT WSFTVMUTNE Implementation Latency

    (mean) Messages Connections Connection Timeouts &SMBOH $PXCPZ NT       +BWB 8FCCJU NT       /PEFKT XFCTPDLFU  NT        ೥ɿಉ࣌ ઀ଓ ඵؒϝοηʔδ઀ଓ ඵ࿈ଓՔಇ
  2. ৘ใͷऩूํ๏  w 2JJUB
 IUUQRJJUBDPNUBHTFSMBOH w -FBSOZPVTPNF&SMBOHGPSHSFBUHPPE
 ͷ೔ຊޠ༁
 IUUQXXXZNPUPOHQPPDPNXPSLTMZTFKBJOEFYIUNM w

    &YQMPSF(JU)VC
 IUUQTHJUIVCDPNUSFOEJOH MFSMBOHTJODFNPOUIMZ w )PX*4UBSU &SMBOH8JUI'SFE)FCFSU 
 IUUQXXXIPXJTUBSUPSHQPTUTFSMBOH
  3. υΩϡϝϯτ  w OPEFTͷಡΈํ nodes(Arg) -> Nodes Types: Arg =

    NodeType | [NodeType] NodeType = visible | hidden | connected | this | known Nodes = [node()]  OPEFTؔ਺ʹ͸"SHܕͷҾ਺Λ౉͢ɻ
 "SH͸/PEF5ZQFܕ·ͨ͸/PEF5ZQFܕͷϦετ
 /PEF5ZQFܕ͸্ड़ͷ௨Γɻ  ໭Γ஋͸ɺ/PEFTܕΛฦ͢ɻ
 /PEFT͸OPEFͷϦετɻ
  4. ։ൃ؀ڥ 04 w 8JOEPXT
 IUUQXXXFSMBOHPSHEPXOMPBEIUNM
 ͔Β#JOBSZ'JMFΛμ΢ϯϩʔυͯ͠Πϯετʔϧ w -JOVY
 %JTUSJCVUJPOຖʹҟͳΔɻ ZVNBQU

    
 ύοέʔδ͕ࡉ͔͘෼ׂ͞Ε͍ͯΔҝɺιʔείʔυ͔Β
 Πϯετʔϧͨ͠ํ͕ྑ͍ w .BD049
 CSFXJOTUBMMFSMBOH
  5. ։ൃ؀ڥ ΤσΟλ w &NBDT σϑΥϧτͷ։ൃ؀ڥιʔείʔυʹόϯυϧ  w 7JN w 4VCMJNF5FYU

    w ϝϞா 8JOEPXTͷਓ͸͜ΕΛ࢖͍ͬͯΔͱฉ͍ͨ͜ͱ͕͋Δɻ  w *OUFMMJ+ FSMBOHQMVHJO
  6. ։ൃ؀ڥ &SMBOH051ΛϏϧυ w ιʔείʔυ͔ΒίϯύΠϧ͢Δͷ͕Φεεϝɻ w LFSM IUUQTHJUIVCDPNZSBTILLFSM Λ࢖ͬͯίϯύΠϧ w ෳ਺ͷόʔδϣϯΛ؅ཧͯ͘͠ΕΔ

    w SCFOWOPEFCSFXͷ༷ͳ؅ཧϚωʔδϟʔ w ೔ຊޠͷղઆهࣄ w LFSMͰ(JU)VC൛ͷ&SMBOHΛΠϯετʔϧ͢Δ
 IUUQRJJUBDPNKKCEYJUFNTGECBGDFDBCE
  7. ։ൃ؀ڥ ςετ w ςετ w &6OJU ୯ମςετ  w $PNNPO5FTUT

    γεςϜςετ  w ςετ༻ϥΠϒϥϦ w .FDL ϞοΫϥΠϒϥϦ
  8. ։ൃ؀ڥ πʔϧ w &%PD w ϓϩάϥϜͷυΩϡϝϯτΛੜ੒ w %JBMZ[FS w ܕղੳπʔϧ

    w DPWFS w ΧόϨοδ w YSFG w ࢖ΘΕͳ͘ͳͬͨؔ਺΍ະఆٛͷؔ਺Λऔಘ
  9. ։ൃ؀ڥ σόοά w JPGPSNBUʹΑΔσόοά w ϩΨʔΛ࢖͏ MBHFS 
 IUUQTHJUIVCDPNCBTIPMBHFS
 


    σόοΨʔ͕ඞཁͳ΄Ͳ΍΍͍͜͠ॲཧΛॻ࣌͘఺ Ͱؒҧ͍ͬͯΔͱฉ͍ͨهԱ͕ɻɻɻ
  10. /VNCFS ‣ ੔਺ ‣ ਐ਺ ‣ ਐ਺ ‣ ਐ਺ ‣

    ਐ਺ ‣ ਐ਺ ‣ ුಈখ਺఺ Eshell V6.3 (abort with ^G) 1> 128. 128 2> 16#1f. 31 3> 2#10. 2 4> 32#10. 32 5> 1.234E-10. 1.234e-10 6> 1.234E+10. 1.234e10
  11. "UPN w $΍+BWBͷྻڍܕʹ͍ۙɺ·ͨ͸3VCZͷ4ZNCPM w ($ର৅֎ͳͷͰ࢖͍͗͢ʹ஫ҙ w ྫ  w IFMMP

    w IFMMP@XPSME w .POEBZ w IFMMPXPSME 10.1 Memory
 http://www.erlang.org/doc/efficiency_guide/advanced.html
  12. #JOBSZ w &SMBOH051͸όΠφϦΛޮ཰తʹѻ͏ࣄ͕ग़དྷ Δ༷ʹͳ͍ͬͯΔ
 ੵۃతʹ#JOBSZΛ࢖͏΂͖ w ྫ  w 

      w "#$ Eshell V6.3 (abort with ^G) 1> <<65,66,67>>. <<"ABC">> 2>
  13. 'VO w ؔ਺ΦϒδΣΫτ w ແ໊ؔ਺Λ࡞੒͢Δࣄ͕ग़དྷΔ w ྫ  w 'VOGVO

    9 9 FOE Eshell V6.3 (abort with ^G) 1> Fun1=fun(X) -> X+1 end. #Fun<erl_eval.6.90072148> 2> Fun1(100). 101
  14. 1PSU w ϑΝΠϧσΟεΫϦϓλɺιέοτͷΑ͏ʹɺ &SMBOH051͕֎෦ͱ΍ΓͱΓग़དྷΔ༷ʹ
 ͢Δҝͷ΋ͷ w ྫ  w 1PQFO@QPSU

    \TQBXO MT^ <>  w 11PSU Eshell V6.3 (abort with ^G) 1> P = open_port({spawn, "ls"}, []). #Port<0.550> 2> flush(). Shell got {#Port<0.550>, {data,"main.yml\n"}} ok
  15. 1JE w ϓϩηεࣝผࢠ w ྫ  w 1JETQBXO PT DNE

    <lMT>  w 1JE Eshell V6.3 (abort with ^G) 1> Func1=fun(X) -> X+1 end. #Fun<erl_eval.6.90072148> 2> Parent=self(). <0.32.0> 3> Pid1 = spawn(fun() -> erlang:send(Parent, Func1(100)) end). <0.36.0> 4> flush(). Shell got 101 ok
  16. .BQ w ,FZ7BMVFͷσʔλܕ w ϑΥʔϚοτ\,FZ7BMVF  ,FZ/7BMVF/^ w ྫ 

    w .\OBNFFSMBOH EBUF\GFC ^^ Eshell V6.3 (abort with ^G) 1> M1 = #{name=>erlang, date=>{feb, 14}}. #{date => {feb,14},name => erlang} 2> #{name := N1} = M1. #{date => {feb,14},name => erlang} 3> N1. erlang
  17. -JTU ‣ Add head 1 2 3 0 list =

    [0] + [1,2,3] 0 1 2 3 list = ‣ Add tail list =[1,2,3] + [4] 1 2 3 4 1 2 3 4 1 2 3 4 list = ৽͘͠ϦετΛ࡞੒ 0 ௥Ճ ௥Ճ
  18. 4USJOH w ੔਺ͷϦετ w ೋॏҾ༻ූ l ͰғΉ w ྫ 

    w lBCD w <  >BCD w <B C D>BCD Eshell V6.3 (abort with ^G) 1> "abc" =:= [97,98,99]. true 2>
  19. 3FDPSE w ಛघͳ5VQMF w 5VQMF͸ཁૉͷҐஔͰಛఆ͢Δͷʹରͯ͠ɺ3FDPSE͸໊લͰҐ ஔΛಛఆ͢Δɻ w ྫ  w

    SE JUFN \JE OBNF QSJDF^  w "QQMFJUFN\JE OBNF"QQMF QSJDF ^ w JUFN\OBNF/BNF^"QQMF
  20. 3FDPSE Eshell V6.3 (abort with ^G) 1> rd(person, {name =

    "", phone = [], address}). person 2> P = #person{name = "Joe", phone = [0,8,2,3,4,3,1,2]}. #person{name = "Joe", phone = [0,8,2,3,4,3,1,2], address = undefined} 3> P#person.name. "Joe" 4> P1 = #person{name="Joe", phone=[1,2,3], address="A street"}. #person{name = "Joe",phone = [1,2,3],address = "A street"} 5> P2 = P1#person{name="Robert"}. #person{name = "Robert", phone = [1,2,3], address = "A street"} 6> P3 = #person{name="Joe", phone=[0,0,7], address="A street"}. #person{name = "Joe",phone = [0,0,7],address = "A street"} 7> #person{name = Name} = P3, Name. "Joe"
  21. #PPMFBO w &SMBOHʹ#PPMFBOܕ͸ແ͘ɺUSVFͱGBMTF͸ "UPNܕͰ͋Δɻ w ྫ  w  w

    USVFbUSVF Eshell V6.3 (abort with ^G) 1> 2 =< 3. true 2> true == 'true'. true
  22. 051 ‣ "QQMJDBUJPO#FIBWJPVST ‣ BQQMJDBUJPO ‣ ൚༻051ΞϓϦέʔγϣϯؔ਺ ‣ TVQFSWJTPS ‣

    ൚༻εʔύόΠβϏϔΠϏΞ ‣ HFO@TFSWFS ‣ ൚༻αʔόϏϔΠϏΞ ‣ HFO@FWFOU ‣ ൚༻Πϕϯυॲཧ༻ϏϔΠϏΞ ‣ HFO@GTN ‣ ൚༻༗ݶঢ়ଶػցϏϔΠϏΞ
  23. 051 LW@BQQ LW@TVQ LW@NPOJUPS LW@NBOBHF NOFTJB@TVQ NOFTJB@FWFOU NOFTJB@LFSOFM@TV NOFTJB@DPOUSPMMF NOFTJB@MPDLF

    NOFTJB@NPOJUP NOFTJB@SFDPWF ࠶ىಈઓུ SFTU@GPS@POF TJNQMF@POF@GPS@POF LW@NPOJUPS POF@GPS@POF ΋͠ɺࢠϓϩηε͕ఀࢭͨ͠Β ͦͷϓϩηεͷΈ࠶ىಈ͢Δɻ NOFTJB@DPOUSPMMF NOFTJB@MPDLF NOFTJB@NPOJUP NOFTJB@SFDPWF BQQMJDBUJPO TVQFSWJTPS XPSLFS 4UBSU 4UBSUBOE8BUDI POF@GPS@BMM ΋͠ɺࢠϓϩηε͕ఀࢭͨ͠Βɺ ଞͷશͯͷࢠϓϩηεΛఀࢭͯ͠ɺ͢΂ͯͷࢠϓϩηεΛ࠶ىಈ͢Δɻ
  24. ύλʔϯϚον if_func(N) -> if N =:= 1 -> one; N

    =:= 2 -> two; true -> other end. if_func(1) -> one; if_func(2) -> two; if_func(_) -> other. Λ౉ͨ͠ΒUISFFΛฦ༷͢ʹ͔ͨͬͨ͠Βʁ
  25. ґଘؔ܎ͷղܾ  ϓϩδΣΫτσΟϨΫτϦ಺ʹSFCBSDPOpHΛ ࡞੒ͯ͠ɺґଘؔ܎ͷઃఆΛهड़ \EFQT <
 \DPXCPZ   


    \HJU HJUHJUIVCDPNFYUFOEDPXCPZHJU NBTUFS^^
 >^  SFCBSίϚϯυΛ࢖ͬͯίʔυΛऔಘ͢Δɻ SFCBSHFUEFQT