-

   rss_rss_hh_new

 - e-mail

 

 -

 LiveInternet.ru:
: 17.03.2011
:
:
: 51

:


[ ] Highload Cup,

, 13 2017 . 16:27 +
rus_phantom 16:27

Highload Cup,

HighLoad Cup, HTTP . 5 Go, 52 295, .



Afinogen , . API : (User), (Location) (Visit). API , , 2 (avg) , (visits). , . , , API 18 25 1 2010 . .


API:


  • GET //
  • POST //
  • POST //new
  • GET /users//visits
  • GET /locations//avg


. ( ) - , . . , . 1 , 100 10 , 1. , , , , . :


type Visit struct {  // overall 40 bytes
    Id        int    // 8 bytes
    Location  int    // 8 bytes
    User      int    // 8 bytes
    VisitedAt int    // 8 bytes
    Mark      int    // 8 bytes
}

type User struct {    //overall 133 bytes
    Id        int       // 8 bytes
    Email     string    // 22 bytes + 16 bytes
    FirstName string    // 12 bytes + 16 bytes
    LastName  string    // 18 bytes + 16 bytes
    Gender    string    // 1 byte   + 16 bytes
    Birthdate int       // 8 bytes
}

type Location struct { // overall 105 bytes
    Id       int       // 8 bytes
    Place    string    // 11 bytes + 16 bytes
    Country  string    // 14 bytes + 16 bytes
    City     string    // 16 bytes + 16 bytes
    Distance int       // 8 bytes
}

string " " + " string". , 518 . , 4 .


, , , . , .zip 10 . 200 , + 1.5 . .


, , , . 3 : GET , avg ( ) visits ( ), ( POST ) GET , . - GET POST , - .


, , id 1, :


type Database struct {
    usersArray     []*User
    locationsArray []*Location
    visitsArray    []*Visit
    usersMap       map[int]*User
    locationsMap   map[int]*Location
    visitsMap      map[int]*Visit
}

, , . , id , . , , , .



, avg visits User Location, id . Visits, , Visit, /.


"container/list" , , . / , 10 1, Visit Location User 10. 10 . , :


package main

import (
    "fmt"
    "runtime"
    "runtime/debug"
    "container/list"
)

func main() {
    debug.SetGCPercent(-1)
    runtime.GC()
    m := &runtime.MemStats{}
    runtime.ReadMemStats(m)
    before := m.Alloc

    for i:=0;i<1000;i++ {
        s := make([]int, 0)
        for j:=0;j<10;j++ {
            s = append(s, 0)
        }
    }
    runtime.ReadMemStats(m)
    fmt.Printf("Alloced for slices %0.2f KB\n", float64(m.Alloc - before)/1024.0)

    runtime.GC()
    runtime.ReadMemStats(m)
    before = m.Alloc

    for i:=0;i<1000;i++ {
        s := list.New()
        for j:=0;j<10;j++ {
            s.PushBack(1);
        }
    }
    runtime.ReadMemStats(m)
    fmt.Printf("Alloced for lists %0.2f KB\n", float64(m.Alloc - before)/1024.0)

}

:


Alloced for slices 117.19 KB
Alloced for lists 343.75 KB

1000 1000 10 , . 10 , , 8 16 . 3 , , , .


visits. , , , .



http , , fasthttp. http fasthttp. , API.


/ json. easyjson, / + "encoding/json" API. Easyjson , . . , , , , easyjson , - .



API POST , , ?


. , . .



5 , , Go, 52 295 . , , - .


GitHub

Original source: habrahabr.ru (comments, light).

https://habrahabr.ru/post/337868/

:  

: [1] []
 

:
: 

: ( )

:

  URL