Documentation ¶
Index ¶
Constants ¶
const ( // CompressNone disables connection compression. // // CompressNone may be used in the following cases: // // * If network bandwidth between client and server is unlimited. // * If client and server are located on the same physical host. // * If other CompressType values consume a lot of CPU resources. // CompressNone = CompressType(fastrpc.CompressNone) // CompressFlate uses compress/flate with default // compression level for connection compression. // // CompressFlate may be used in the following cases: // // * If network bandwidth between client and server is limited. // * If client and server are located on distinct physical hosts. // * If both client and server have enough CPU resources // for compression processing. // CompressFlate = CompressType(fastrpc.CompressFlate) // CompressSnappy uses snappy compression. // // CompressSnappy vs CompressFlate comparison: // // * CompressSnappy consumes less CPU resources. // * CompressSnappy consumes more network bandwidth. // CompressSnappy = CompressType(fastrpc.CompressSnappy) )
Variables ¶
var ( // ErrTimeout is returned from timed out calls. ErrTimeout = fastrpc.ErrTimeout // ErrPendingRequestsOverflow is returned when Client cannot send // more requests to the server due to Client.MaxPendingRequests limit. ErrPendingRequestsOverflow = fastrpc.ErrPendingRequestsOverflow )
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct { // Addr is the httpteleport Server address to connect to. Addr string // CompressType is the compression type used for requests. // // CompressFlate is used by default. CompressType CompressType // Dial is a custom function used for connecting to the Server. // // fasthttp.Dial is used by default. Dial func(addr string) (net.Conn, error) // TLSConfig is TLS (aka SSL) config used for establishing encrypted // connection to the server. // // Encrypted connections may be used for transferring sensitive // information over untrusted networks. // // By default connection to the server isn't encrypted. TLSConfig *tls.Config // MaxPendingRequests is the maximum number of pending requests // the client may issue until the server responds to them. // // DefaultMaxPendingRequests is used by default. MaxPendingRequests int // MaxBatchDelay is the maximum duration before pending requests // are sent to the server. // // Requests' batching may reduce network bandwidth usage and CPU usage. // // By default requests are sent immediately to the server. MaxBatchDelay time.Duration // Maximum duration for full response reading (including body). // // This also limits idle connection lifetime duration. // // By default response read timeout is unlimited. ReadTimeout time.Duration // Maximum duration for full request writing (including body). // // By default request write timeout is unlimited. WriteTimeout time.Duration // ReadBufferSize is the size for read buffer. // // DefaultReadBufferSize is used by default. ReadBufferSize int // WriteBufferSize is the size for write buffer. // // DefaultWriteBufferSize is used by default. WriteBufferSize int // contains filtered or unexported fields }
Client teleports http requests to the given httpteleport Server over a single connection.
Use multiple clients for establishing multiple connections to the server if a single connection processing consumes 100% of a single CPU core on either multi-core client or server.
func (*Client) DoDeadline ¶
func (c *Client) DoDeadline(req *fasthttp.Request, resp *fasthttp.Response, deadline time.Time) error
DoDeadline teleports the given request to the server set in Client.Addr.
ErrTimeout is returned if the server didn't return response until the given deadline.
func (*Client) DoTimeout ¶
func (c *Client) DoTimeout(req *fasthttp.Request, resp *fasthttp.Response, timeout time.Duration) error
DoTimeout teleports the given request to the server set in Client.Addr.
ErrTimeout is returned if the server didn't return response during the given timeout.
func (*Client) PendingRequests ¶
PendingRequests returns the number of pending requests at the moment.
This function may be used either for informational purposes or for load balancing purposes.
type Server ¶
type Server struct { // Handler must process incoming http requests. // // Handler mustn't use the following features: // // - Connection hijacking, i.e. RequestCtx.Hijack // - Streamed response bodies, i.e. RequestCtx.*BodyStream* Handler fasthttp.RequestHandler // CompressType is the compression type used for responses. // // CompressFlate is used by default. CompressType CompressType // Concurrency is the maximum number of concurrent goroutines // with Server.Handler the server may run. // // DefaultConcurrency is used by default. Concurrency int // TLSConfig is TLS (aka SSL) config used for accepting encrypted // client connections. // // Encrypted connections may be used for transferring sensitive // information over untrusted networks. // // By default server accepts only unencrypted connections. TLSConfig *tls.Config // MaxBatchDelay is the maximum duration before ready responses // are sent to the client. // // Responses' batching may reduce network bandwidth usage and CPU usage. // // By default responses are sent immediately to the client. MaxBatchDelay time.Duration // Maximum duration for reading the full request (including body). // // This also limits the maximum lifetime for idle connections. // // By default request read timeout is unlimited. ReadTimeout time.Duration // Maximum duration for writing the full response (including body). // // By default response write timeout is unlimited. WriteTimeout time.Duration // ReduceMemoryUsage leads to reduced memory usage at the cost // of higher CPU usage if set to true. // // Memory usage reduction is disabled by default. ReduceMemoryUsage bool // ReadBufferSize is the size for read buffer. // // DefaultReadBufferSize is used by default. ReadBufferSize int // WriteBufferSize is the size for write buffer. // // DefaultWriteBufferSize is used by default. WriteBufferSize int // Logger used for logging. // // Standard logger from log package is used by default. Logger fasthttp.Logger // PipelineRequests enables requests' pipelining. // // Requests from a single client are processed serially // if is set to true. // // Enabling requests' pipelining may be useful in the following cases: // // - if requests from a single client must be processed serially; // - if the Server.Handler doesn't block and maximum throughput // must be achieved for requests' processing. // // By default requests from a single client are processed concurrently. PipelineRequests bool // contains filtered or unexported fields }
Server accepts requests from httpteleport Client.
func (*Server) ListenAndServe ¶
ListenAndServe serves httpteleport requests accepted from the given TCP address.