USE_FASE_ONLINE_MAP = true CHANGE_USER_STATE_IN_REAL_TIME = true POLL_WAIT_TIME = 5 //MULTI_CAST_BUFFER_SIZE = 1 << 19 //CHANNEL_LOCKS = 8 //CHANNEL_SCAVENGER = 8 ) var ( all_channel *AllChannel // byte pool: 4K []byte each of which can hold 8K of data byte_pool = bytepool.New(4096, 8192) // timingwheel wheel_seconds = utils.NewTimingWheel(1*time.Second, 600) wheel_milliseconds = utils.NewTimingWheel(10*time.Millisecond, 2) ServerDebug bool Config *lib.GlobalConfig CHANNEL_LOCKS = int(runtime.NumCPU()) CHANNEL_SCAVENGER = int(runtime.NumCPU()) ) type AllChannel struct { RLock *sync.RWMutex
func newRouter(c *Configuration) *Router { initGeoIP(c) bp := bytepool.New(c.bodyPoolSize, int(c.maxBodySize)) return &Router{c, bp} }
// more than a little ugly... func InitInvalidPool(poolSize, bufferSize int) { invalidBytePool = bytepool.New(poolSize, bufferSize) }
"encoding/gob" "github.com/viki-org/bytepool" "log" "net/http" "os" "path" "seedcdn/core" "seedcdn/demultiplexer" ) type CacheHeader struct { Header http.Header Status int } var pool = bytepool.New(1024, 2048) func Run(context *core.Context, res http.ResponseWriter, next core.Middleware) { if fromDisk(res, context) { core.Stats.CacheHit() return } core.Stats.CacheMiss() demultiplexer.Demultiplex(context, toResponse(res), toDisk(context)) } func fromDisk(res http.ResponseWriter, context *core.Context) bool { headerFile, err := os.Open(context.HeaderFile) if err != nil { return false }
package validation import ( "fmt" "github.com/viki-org/bytepool" "net/http" "strconv" ) var invalidBytePool = bytepool.New(1, 1024) // more than a little ugly... func InitInvalidPool(poolSize, bufferSize int) { invalidBytePool = bytepool.New(poolSize, bufferSize) } type InvalidResponse struct { buffer *bytepool.Item } func NewResponse(errors map[string][]*Definition) *InvalidResponse { buffer := invalidBytePool.Checkout() //am I really doing this in a public repo?! buffer.WriteByte(byte('{')) for field, definitions := range errors { buffer.WriteString(fmt.Sprintf("%q:[", field)) for _, definition := range definitions { buffer.WriteString(fmt.Sprintf("%q,", definition.message)) } buffer.Position(buffer.Len() - 1) //strip trailing comma buffer.WriteString("],")