Detailed testing of pressure CodeBenchmark

CodeBenchmarkIs a high performance visual concurrent test components may be concurrently tested by any component or service logic code; final component to display the test results by a visual manner, can see the specific case of concurrent treatment and the delay test results Distribution. Components can be not only a single service or concurrent test logic may also be performed simultaneously for a plurality of different logic code packet concurrent with the pressure sensing embodiment, the final results in the optimum display performance difference between them and the different concurrency. Next, how to use this component of the service logic code or concurrent testing.

Build a test project

By vsor vscodeconstruct a console project and then reference the component (references, the latest version BeetleX.CodeBenchmark)

Install-Package BeetleX.CodeBenchmark -Version 1.0.8

A pressure sensing implement HTTP

After the reference component can be prepared by specific test, must meet the test assembly preparation of the test requirements, it is necessary to implement an interface to write test code, the interface is described as follows:

    public interface IExample:IDisposable
    {
        void Initialize(Benchmark benchmark);
        Task Execute();
    }

Pressure sensing logic HTTP Code

    [System.ComponentModel.Category("TCP")]
    class HttpGet : IExample
    {
        public void Dispose()
        {          
        }

        public async Task Execute()
        {
            var result = await _httpHandler.json();
        }

        public void Initialize(Benchmark benchmark)
        {
            if(_httpApi==null)
            {
                _httpApi = new BeetleX.Http.Clients.HttpClusterApi();
                _httpApi.DefaultNode.Add("http://192.168.2.19:8080");
                _httpHandler = _httpApi.Create<IHttpHandler>();
            }
        }

        static BeetleX.Http.Clients.HttpClusterApi _httpApi;

        static IHttpHandler _httpHandler;

        [BeetleX.Http.Clients.FormUrlFormater]
        public interface IHttpHandler
        {
            // http://host/json
            Task<string> json();
        }
    }

Create a Request instance initialized when the concurrent httprequest object HttpClusterApiis a thread-safe objects we only need to build a static; components will be built for the first instance of a concurrent.

Start pressure measurement

When after the test write need to be tested, i.e., test management can be opened by simple code

            Benchmark = Benchmark new new Benchmark (); 
            benchmark.Register ( typeof (Program) .assembly); 
            benchmark.Start (); // Open the local management services, the service channel is the default port 9090 
            IF (== Environment.OSVersion.Platform the PlatformID .Win32NT) 
                benchmark.OpenWeb ();

Do a bit of code to determine if the current system is windowsthen automatically open the browser to access the service (Since the service is based on the realization vue, there are some older browser compatibility problems, we recommend using a modern browser).

Management and Testing

When the open after the service through the browser can manage test cases, specific interface is as follows:

In the administration interface you only need to select the test cases and add concurrency test pressure which can be measured, the following is open 10 concurrent 10 seconds and run test cases:

After running to see the number of concurrent completion and average RPS, hit test use cases can see the delay distribution, the distribution may know most of the processing area at that time.

Comparison of different concurrent

Many times the need for a service of different concurrent test, so the service can be observed most concurrent processing capability under the concurrent amount; to add multiple components to support concurrent test groups and tested and the results compared.

Under this hardware and test scenarios, apparently dynamometer test results up to 8 concurrent

Through the test plan can be designed for concurrency control service situation. Next, try to change the environment under the same test

You may soon be able to measure the optimum effect under different concurrent processing environment through tools

The multiple logical concurrent performance comparison can

Pressure sensing assembly embodiment also supports multi contrast, only need to select a plurality of test cases when the test. Next simply test different jsonperformance comparison of sequence assembly. Test, respectively Newtonsoft.Json, Utf8Json, SwifterJsonand a spanJsoncorresponding code is as follows:

  • Newtonsoft.Json

    [System.ComponentModel.Category("Serializer-Stream")]
      class Newtonsoft_Stream : CodeBenchmark.IExample
      {
          public void Dispose()
          {
    
          }
          public Task Execute()
          {
              memoryStream.Position = 0;
              var users = User.List(10);
              jsonSerializer.Serialize(jsonTextWriter, users);
              jsonTextWriter.Flush();
    
              return Task.CompletedTask;
          }
    
          private System.IO.MemoryStream memoryStream;
    
          private System.IO.StreamWriter streamWriter;
    
          private Newtonsoft.Json.JsonSerializer jsonSerializer;
    
          private Newtonsoft.Json.JsonTextWriter jsonTextWriter;
    
          public void Initialize(Benchmark benchmark)
          {
              memoryStream = new System.IO.MemoryStream();
              jsonSerializer = new Newtonsoft.Json.JsonSerializer();
              streamWriter = new StreamWriter(memoryStream);
              jsonTextWriter = new Newtonsoft.Json.JsonTextWriter(streamWriter);
          }
      }
  • Utf8Json

    [System.ComponentModel.Category("Serializer-Stream")]
      class Utf8Json_Stream : CodeBenchmark.IExample
      {
          public void Dispose()
          {
          }
    
          public async Task Execute()
          {
              MemoryStream.Position = 0;
              var users = User.List(10);
              await Utf8Json.JsonSerializer.SerializeAsync<List<User>>(MemoryStream, users);
              TextWriter.Flush();
          }
    
          private System.IO.MemoryStream MemoryStream = new System.IO.MemoryStream();
    
          private System.IO.TextWriter TextWriter;
    
          public void Initialize(Benchmark benchmark)
          {
              TextWriter = new System.IO.StreamWriter(MemoryStream, Encoding.UTF8);
          }
      }
  • SwifterJson

    [System.ComponentModel.Category("Serializer-Stream")]
      class Swifter_Stream : CodeBenchmark.IExample
      {
          public void Dispose()
          {
          }
          public async Task Execute()
          {
              MemoryStream.Position = 0;
              var users = User.List(10);
              await Swifter.Json.JsonFormatter.SerializeObjectAsync<List<User>>(users, TextWriter);
              TextWriter.Flush();
          }
    
          private System.IO.MemoryStream MemoryStream = new System.IO.MemoryStream();
    
          private System.IO.TextWriter TextWriter;
    
          public void Initialize(Benchmark benchmark)
          {
              TextWriter = new System.IO.StreamWriter(MemoryStream, Encoding.UTF8);
          }
      }
  • SpanJson

     [System.ComponentModel.Category("Serializer-Stream")]
      class Span_Stream : CodeBenchmark.IExample
      {
          public void Dispose()
          {
    
          }
    
          public async Task Execute()
          {
              var users = User.List(10);
              MemoryStream.Position = 0;
              await SpanJson.JsonSerializer.NonGeneric.Utf8.SerializeAsync(users, MemoryStream);
          }
    
          private System.IO.MemoryStream MemoryStream = new System.IO.MemoryStream();
    
          public void Initialize(Benchmark benchmark)
          {
    
          }
      }

Next to this logic several concurrent pressure measurements 2,4,8,16 and 32 (Note: caution here, if it is the case of pressure measurement data concurrent memory operations should not exceed the number of logical cores of the CPU, otherwise it will cause the component count Timer may not have the chance to trigger or trigger delay)

 

 

Here CodeBenchmarkuse to explain the complete, if interested can follow https://github.com/IKende/CodeBenchmarkDoc

Guess you like

Origin www.cnblogs.com/smark/p/11504653.html