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

Go駆動開発で超速Pushエンジンを作った話

 Go駆動開発で超速Pushエンジンを作った話

Go Conference 2014 spring で発表した資料。
受託開発に持ち込んだ事例紹介。
http://connpass.com/event/6370/

kadota kyohei

May 31, 2014
Tweet

More Decks by kadota kyohei

Other Decks in Technology

Transcript

  1. • ͜ͳ͍ͩSleipnir 6͕ग़·ͨ͠ʂ • ڞಉ։ൃ෦ • اۀ༷͔Βͷडୗ։ൃΛߦ͏෦ॺ • ࣮੷঺հ -

    http://biz.fenrir-inc.com • Sleipnir΁ͷ͝ҙݟ͸ެࣜαΠτ͔Β ϑΣϯϦϧגࣜձࣾ
  2. • ࠷ॳ͸PHPͰ࣮૷ • ਫ४Λຬͨͤͳ͍ • ਺ेສ௨஌ʹ଱͑ΒΕͳ͍ • ઃܭ͕·͔ͣͬͨ • PHPѱ͘ͳ͍

    performance problems… ඵ ඵ ඵ ඵ ඵ ສ ສ ສ ສ
  3. GoΛ޷Ήཧ༝(౰࣌) • Rob Pike΍Russ Cox͕ࢀՃͯ͠Δ • Plan 9ʹ΋ؔΘ͓ͬͯΒΕ·ͨ͠ • Alef,

    Limbo͔Βଓ͘CSPྑ͍ • ඪ४ύοέʔδ΋ॆ࣮ͯͦ͠͏(งғؾ)
  4. net/rpcύοέʔδ // ܾ·ͬͨܗͷϝιουΛΤΫεϙʔτ͓͍ͯͯ͠ fund (agent *Agent) Broadcast(r *Request, res *Response)

    error { return nil } ! // ผͷϊʔυ͔ΒrpcΛίʔϧ͢Δ c, _ := rpc.Dial(“net”, “localhost:17030”) err := c.Call(“Broadcast”, r, &res)
  5. ։͍͍ͯΔagentΛબ୒ // ϦΫΤετ༻νϟωϧΛ1ຊ͚ͩ༻ҙ req := make(chan *Request, bufSize) ! //

    ؅ཧ͢Δϊʔυ෼ɺϦΫΤετ༻νϟωϧ͔Βड৴͢ΔΰϧʔνϯΛىಈ͓ͯ͘͠ for agent := range agents { go func(c chan *Request){ _ = <-c }(req) } ! // νϟωϧʹϦΫΤετΛ౤͛Δͱ଴ػ͍ͯ͠ΔΰϧʔνϯͷͲΕ͔͕र͏ select { case req <- newReq: …. case <-time.After(timeoutInterval): …
  6. ෳ਺·ͱΊͯૹ৴ que := make(chan *Message, bufSize) … // ctlr͔ΒͷϦΫΤετड৴ req

    := <-que msgs = append(msgs, req) for len(que) > 0 { msgs = append(msgs, <-que) } conn.WriteMessages(msgs)
  7. ςετίʔυ // ςετ༻Fake APNsαʔό(ຊ෺͸gateway.push.apple.com:2195)Λىಈ s := apnstest.NewServer(func(w io.Writer, msg *apns.Message)

    { // wʹԿ͔Write͢Ε͹Τϥʔͱͯ͠ΫϥΠΞϯτʹฦ͢ // Կ΋͠ͳ͚Ε͹ਖ਼ৗʹ௨஌׬ྃ }) cli := NewClient(s.Addr) msg := newMessage() ! que := make([]<-chan error, b.N) for i := 0; i < b.N; i++ { que[i] = cli.Go(msg) }