tps

package
v5.0.0+incompatible Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 11, 2018 License: Apache-2.0 Imports: 5 Imported by: 0

README

tps

tps statistics requests per second.

Usage

import tps "github.com/henrylee2cn/tp-ext/plugin-tps"

Test
package tps

import (
	"testing"
	"time"

	tp "github.com/henrylee2cn/teleport"
)

type Call struct {
	tp.CallCtx
}

func (*Call) Test(*struct{}) (*struct{}, *tp.Rerror) {
	return nil, nil
}

type Push struct {
	tp.PushCtx
}

func (*Push) Test(*struct{}) *tp.Rerror {
	return nil
}

func TestTPS(t *testing.T) {
	tp.SetLoggerLevel("OFF")
	// Server
	srv := tp.NewPeer(tp.PeerConfig{ListenPort: 9090}, NewTPS(5))
	srv.RouteCall(new(Call))
	srv.RoutePush(new(Push))
	go srv.ListenAndServe()
	time.Sleep(1e9)

	// Client
	cli := tp.NewPeer(tp.PeerConfig{})
	sess, err := cli.Dial(":9090")
	if err != nil {
		if err != nil {
			t.Error(err)
		}
	}
	var (
		rerr   *tp.Rerror
		ticker = time.NewTicker(time.Millisecond * 10)
	)
	for i := 0; i < 1<<10; i++ {
		<-ticker.C
		rerr = sess.Call("/call/test", nil, nil).Rerror()
		if rerr != nil {
			t.Error(rerr)
		}
		rerr = sess.Push("/push/test", nil)
		if rerr != nil {
			t.Error(rerr)
		}
	}
}

test command:

go test -v -run=TestTPS

Documentation

Overview

Package tps statistics requests per second

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type TPS

type TPS struct {
	// contains filtered or unexported fields
}

func NewTPS

func NewTPS(intervalSecond uint32) *TPS

func (*TPS) Name

func (t *TPS) Name() string

func (*TPS) PostReadPushBody

func (t *TPS) PostReadPushBody(ctx tp.ReadCtx) *tp.Rerror

func (*TPS) PostReg

func (t *TPS) PostReg(h *tp.Handler) error

func (*TPS) PostWriteReply

func (t *TPS) PostWriteReply(ctx tp.WriteCtx) *tp.Rerror

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL