Alice52 / c-tutorial

The repository is about c, including c, csharp, cpp.
MIT License
0 stars 0 forks source link

[resume] slow performance sending queue message #20

Open Alice52 opened 4 years ago

Alice52 commented 4 years ago

step

  1. reproduce, make sure it can produce in env.

  2. find URL in this action

  3. analysis each request time cost

  4. find out where the time spend

  5. look into why it spends so much time

  6. look into which statement slow, why

    • send to queue
    _logger.LogError("send:  zack 1");
    await messageSender.SendAsync(message);
    _logger.LogError("send:  zack 2")
  7. do search for relevant syntax feature

    • SendAsync will create connection with server due to its tolerate error, but it will spend lots of time
    • so it will heal the connection if it is unavailable
  8. analysis


2627.3842ms 
------
buyin       Send        2020-04-02 15:08:15.1928        2020-04-02 15:08:15.4540        2612   
tool        receive     2020-04-02 15:08:15.4540        2020-04-02 15:08:15.6398        1858
tool        send        2020-04-02 15:08:15.6398        2020-04-02 15:08:15.8337        1939
buyin       receive     2020-04-02 15:08:15.8337        2020-04-02 15:08:16.2407        4070

--------------------------------------------------------------------------------        10479

buyin       Send        2020-04-02 15:08:16.2407        2020-04-02 15:08:16.6921        4514
tool        receive     2020-04-02 15:08:16.6921        2020-04-02 15:08:16.8956        2035
tool        send        2020-04-02 15:08:16.8956        2020-04-02 15:08:17.1060        2104
buyin       receive     2020-04-02 15:08:17.1060        2020-04-02 15:08:17.4967        3907

--------------------------------------------------------------------------------        12560

solution

services.AddSingleton<AzureServiceBusUtil>();
services.AddSingleton<TopicClient>();

services.AddSingleton(provider =>
{
    Func<string, string, TopicClient> func = (connectionString, entityName) => 
        {
            return  connectionString == null || entityName == null ? null:new TopicClient(connectionString, entityName);
        };
        return func;
});
_tableFillCreditRequestTopicClient = topicClientFactory(_tableFillCreditConnectionString, _tableFillCreditRequestTopic);

concept

  1. pool: every thing can be re-used should be pooled, such as Thread.

more

  1. IO: MER, NET, DIST IO
  2. load balance

reference

  1. https://docs.microsoft.com/en-us/azure/service-bus-messaging/service-bus-performance-improvements?tabs=net-standard-sdk#reusing-factories-and-clients
Alice52 commented 4 years ago

solution1

  1. use factory to maintain this connection
  2. inject as singleton
  3. use factory in constructor: the class in singleton, so the client created in constructor will also be singleton in application lifecycle.

sample code

solution2

  1. create different client and inject in IOC container