Use BeetleX.NetBenchmark to test TCP,HTTP, and Websocket services

NetBenchmark is an open source component tailored for network service pressure testing, which provides TCP,HTTP, and Web ocket stress testing infrastructure; in order to better meet business requirements, components do not provide a way to configure the source of UI information (after all, this can only be a limited test), but rather users develop their own logic code to conduct specific business tests.Components are based on netstandard2.0 and can be run on.NET CORE as well as.NET FX. The next section describes the use of groups.

Reference Component

https://www.nuget.org/packages/BeetleX.NetBenchmark/

Github: https://github.com/IKende/NetBenchmark

TCP Test

The component uses the Benchmark.Tcp method to build an example of TCP manometry as follows:

public static Runner Tcp<Packet, Token>(string host, int port, int connections,
    Func<BeetleX.Clients.AwaiterClient, Token, Task> handler)
    where Packet : BeetleX.Clients.IClientPacket, new()
    where Token : new()

Method with two generic parameters

  • Packet

    Protocol analyzer, implementing BeetleX.Clients.IClientPacket.

  • Token

    Testing associated objects allows you to formulate related object data status attributes based on your business.

parameter

  • host

    Host Address

  • port

    Service Port

  • connectins

    Number of connections tested concurrently

  • handler

    Test method Func<BeetleX.Clients.AwaiterClient, Token, Task>, test logic invoked each time.

Build a TCP test instance

    class Program
    {
        static void Main(string[] args)
        {
            var data = StringPacket.RamdomString(512);
            var runer = Benchmark.Tcp<StringPacket, Program>("192.168.2.19", 9090, 200,
                async (tcp, token) =>
                {
                    tcp.Send(data);
                    await tcp.Receive();
                }
            );
            runer.Run();
            runer.Print();
        }
    }

The above defines a StringPacket-based custom protocol test, a character protocol interpreter that describes the length of a message in a 4-byte header size.tcp.Send sends a message to the server, while await tcp.Receive waits for the server to respond.

test result

The results can be output to the console in real time using the runer.Print() method, including correct, error, and related network concurrency, and the percentage of responses with different delays at the bottom.

HTTP Test

The component uses the Benchmark.Http method to build an example of HTTP manometry as follows:

public static Runner Http<Token>(Uri host, int connections, Func<IHttpHandler, Token, Task> handler)
    where Token : new()

Method with a generic parameter

  • Token

    Testing associated objects allows you to formulate related object data status attributes based on your business.

parameter

  • host

    Service Address for Testing

  • connections

    Number of connections tested concurrently

  • handler

    Test methods Func<IHttpHandler, Token, Task>, test logic invoked each time.

IHttpHandler

Some simple http call methods are provided

Task Get(string url, Dictionary<string, string> queryString = null);

Task Get(string url, Dictionary<string, string> queryString, Dictionary<string, string> header = null);

Task Post(string url, Dictionary<string, string> queryString, Dictionary<string, string> heaer, Dictionary<string, string> data);

Task Post(string url, Dictionary<string, string> data);

Task PostJson(string url, Dictionary<string, string> queryString, Dictionary<string, string> heaer, object data);

Task PostJson(string url,object data);

Building HTTP Test Instances

    class Program
    {
        static void Main(string[] args)
        {
            var runer = Benchmark.Http<Program>(new Uri("http://192.168.2.19:5000"), 100,
                async (http, token) =>
                {
                    await http.Get("/api/values");
                    await http.PostJson("/api/values", "beetlex.io");
                });
            runer.Run();
            runer.Print();
        }
    }

test result

websocket test

The component uses the Benchmark.Websocketxx method to construct a websocket manometry instance in three ways, DataFrame,Text and Json, as follows:

public static Runner Websocket<Token>(Uri host, int connections, Func<WSClient, Token, Task> handler)
        where Token : new()
public static Runner WebsocketText<Token>(Uri host, int connections, Func<TextClient, Token, Task> handler)
        where Token : new()
public static Runner WebsocketJson<Token>(Uri host, int connections, Func<JsonClient, Token, Task> handler)
        where Token : new()

Build a Web ocket test instance

    class Program
    {
        static void Main(string[] args)
        {
            var runer = Benchmark.WebsocketJson<Program>(new Uri("ws://192.168.2.19:8080"), 100,
                async (ws, token) =>
                {
                    ws.TimeOut = 1000 * 5;
                    ws.Send(new { url = "/json" });
                    var result = await ws.Receive();
                });
            runer.Run();
            runer.Print();
        }
    }

test result

Keywords: Programming network github JSON

Added by jmugambi on Tue, 28 Jan 2020 05:40:38 +0200