GoでKVSを書けるのか
Upcoming SlideShare
Loading in...5
×
 

Like this? Share it with your network

Share

GoでKVSを書けるのか

on

  • 2,064 views

Shibuya.pm #12 発表資料です

Shibuya.pm #12 発表資料です

Statistics

Views

Total Views
2,064
Views on SlideShare
1,715
Embed Views
349

Actions

Likes
1
Downloads
2
Comments
0

9 Embeds 349

http://d.hatena.ne.jp 331
http://moriyoshi.hatenablog.com 6
http://www.slideee.com 4
http://webcache.googleusercontent.com 3
http://translate.googleusercontent.com 1
http://74.125.153.132 1
http://www.slideshare.net 1
https://twitter.com 1
http://www.google.co.jp 1
More...

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

GoでKVSを書けるのか Presentation Transcript

  • 1. Moriyoshi Koizumi
  • 2. net.Listen("tcp", "127.0.0.1:11211") net.Accept()
  • 3. go handleConn(sock);
  • 4. func main() {     if len(os.Args) < 2 {         fmt.Fprintf(os.Stderr, "usage: %s addr:portn", os.Args[0]);         os.Exit(255);     }       l, e := net.Listen("tcp", os.Args[1]);     if e != nil {         error("An error occurred (%s)", e.String());         os.Exit(1);     }       // blocking channel     backend_ch := make(chan *kvsBackendConn);       go backend(backend_ch);       for {         ch, e := l.Accept();         if e != nil {             error("An error occurred (%s)", e.String());             os.Exit(1);         }         go handleConn(ch, backend_ch, false);     }     os.Exit(0) }  
  • 5. opcode := int(header[1]); key_length := (int(header[2]) << 8) | int(header[3]); extra_length := int(header[4]); data_type := int(header[5]); body_length := (int(header[8]) << 24)                 | (int(header[9]) << 16)                 | (int(header[10]) << 8)                 | int(header[11]);
  • 6. func backend(ch <-chan *kvsBackendConn) {     kvs := make(map[string] []byte);     for req := range ch {         switch (req.command) {         case 0: // get             value, e := kvs[string(req.key)];             if e {                 req.resp_ch<- (&kvsBackendConn{command:0, value:value})             } else {                 req.resp_ch<- (&kvsBackendConn{command:0, value:nil})             }             break;         case 1: // set             kvs[string(req.key)] = req.value;             break; backend_ch<-         } (&kvsBackendConn{     } command: 0, } key: key, value: nil, resp_ch: recv_ch }); result := <-recv_ch; resp_extra := make([]byte, 4); if result != nil {     resp = buildResponse(opcode, 0, ...) } else {     resp = buildResponse(opcode, 1, ...) }
  • 7. memslap --test=get --concurrency=4 --binary --verbose --servers=127.0.0.1 --execute-number=100 --initial-load=10000 --tcp-nodelay GOMAXPROCS=1 GOMAXPROCS=2 GOMAXPROCS=3 GOMAXPROCS=4
  • 8. epoll(2)/ Poll server kqueue(2) Write() FD FD FD FD once.Do(startServer) FD FD FD FD Read() FD FD Read() Write() channel communication
  • 9. pipe(2) eventfd(2)
  • 10. moriyoshi