fasthttp

作者: 黑魔术师 | 来源:发表于2018-05-15 19:28 被阅读21次

http://blog.jobbole.com/105927/

func ListenAndServe(addr string, handler RequestHandler) error {
    s := &Server{
        Handler: handler,
    }
    return s.ListenAndServe(addr)
}
 
// ListenAndServe serves HTTP requests from the given TCP addr.
func (s *Server) ListenAndServe(addr string) error {
    ln, err := net.Listen("tcp", addr)
    if err != nil {
        return err
    }
    return s.Serve(ln)
}
 
// Serve blocks until the given listener returns permanent error.
func (s *Server) Serve(ln net.Listener) error {
    ...
    wp := &workerPool{
        WorkerFunc:      s.serveConn,
        MaxWorkersCount: maxWorkersCount,
        LogAllErrors:    s.LogAllErrors,
        Logger:          s.logger(),
    }
    wp.Start()  //启动worker pool
 
    for {
        if c, err = acceptConn(s, ln, &lastPerIPErrorTime); err != nil {
            wp.Stop()
            if err == io.EOF {
                return nil
            }
            return err
        }
        if !wp.Serve(c) {
            s.writeFastError(c, StatusServiceUnavailable,
                "The connection cannot be served because Server.Concurrency limit exceeded")
            c.Close()
            if time.Since(lastOverflowErrorTime) > time.Minute {
                s.logger().Printf("The incoming connection cannot be served, because %d concurrent connections are served. "+
                    "Try increasing Server.Concurrency", maxWorkersCount)
                lastOverflowErrorTime = time.Now()
            }
            time.Sleep(100 * time.Millisecond)
        }
        c = nil
    }
}

相关文章

  • fasthttp

    http://blog.jobbole.com/105927/

  • fasthttp

    转自:https://segmentfault.com/a/1190000009133154 goroutine ...

  • net/http与fasthttp区别

    fasthttp 是 Go 的一款不同于标准库net/http的 HTTP 实现。fasthttp 的性能可以达到...

  • Go FastHttp优雅关闭实现方案

    使用Go开发web服务时很多情况下都会使用号称比标准库快10x的FastHttp, 但fasthttp(版本: 2...

  • fasthttp剖析

    先说点题外话,最近在开发公司级的网关,虽然没有明说,但是对于我们大家来说Nginx就是我们对标的对象。但是说实话,...

  • fasthttp client example

    说明 官方文档关于fasthttp的demo基本都是http server, http client的介绍基本没有...

  • golang workerpool 源码阅读

    今天读了一下 fasthttp 的源码,其中读到了 workpool ,做了一些注释。

  • fasthttp 获取client ip

    用fasthttp 获取客户端ip 的方法是 ctx.RemoteIP().String(),正常情况下这个获取是...

  • fasthttp原理简析

    fasthttp是golang下的一个http框架,顾名思义,与原生的http实现相比,它的特点在于快,按照官网的...

  • 使用 fasthttp 时要注意的两个点

    我们做的是聚合支付系统,使用的是fasthttp 作为http server, http client 也是使用f...

网友评论

      本文标题:fasthttp

      本文链接:https://www.haomeiwen.com/subject/jfcydftx.html