Location>code7788 >text

The solution to the hotspot KEY of SURGING based on the Wooden Boat platform

Popularity:529 ℃/2024-11-20 22:55:29

I. Overview

The previous article introducedHow the surging-based Wooden Boat platform was built as a microserviceThis article will introduce the solution to the hotspot KEY of surging based on the wooden boat platform.

What is Kayak?

Kayak (Kayak) is based on .NET6.0 software environment surging microservices engine for development, the platform contains microservices and Internet of Things platform. Support for asynchronous and responsive programming development , features include object models , devices , products , network components of unified management and microservices platform under the registry , service routing , modules , intermediate services and other management. There are also multi-protocol adaptation (TCP, MQTT, UDP, CoAP, HTTP, Grpc, websocket, rtmp, httpflv, webservice, etc.), through a variety of flexible configurations adapted to access different manufacturers of different protocols and other equipment. And through the device alarms, message notification, data visualization and other functions. Enable you to quickly set up a microservice IoT platform system.

Wooden boat kayal platform open source address:/microsurging/

surging microservices engine Java Open Source Properties:/fanliang11/surging(Surging will move to the back)microsurging(Maintenance carried out)

Second, the problem of caching hotspot Key

  1. What's the problem with hotkey
    It's when a large number of requests go to a fixed key on Redis at a certain instant, resulting in a cache hit, and the requests all hit the DB, overwhelming both the cache service and the DB service, thus affecting the availability of the service;
  2. How's it going to be hot Key?

(1), QPS centralized access frequency accounted for a relatively high proportion of the key will be called hotspot, wooden boat platform will be added based on the routepath access frequency statistics, so that technicians to find out the ranking of the top hotspot KEY.

(2), Value data set is very large resulting in high bandwidth consumption is called hot KEY.

3. Hazards of hotspot KEY

(1) Bandwidth consumption affects other service calls

(2), the request is too large, reducing the performance of other cache calls

(3), cache hit, DB is overwhelmed, causing an avalanche of business.

III. How to solve the problem of hotspot Key based on surging

1. Based onMemoryCachecache interception

It can be used when the access frequency is high, the data is not modified frequently, and there is no need for other microservices to share the call.MemoryCacheCache locally, such as the WoodenBoat platform home page of the product, device, device message statistics, the following figure

You can enable cache blocking by adding the following feature, Mode selection

        [ServiceCacheIntercept(, Key = "GetProductStatistics", CacheSectionType = "ddlCache", EnableL2Cache = false, Mode = , Time = 1, EnableStageCache = true)]
        Task<ApiResult<ProductStatisticsModel>> GetProductStatistics();

The deletion will work, passing in the"GetProducts", "GetProductStatistics", if you need to pass in other parameter values you can add _{0}_{1}, for exampleGetProductsByName_{0}

        [ServiceCacheIntercept(, "GetProducts", "GetProductStatistics", CacheSectionType = "ddlCache", Mode = , EnableStageCache = true)]
        [ServiceLogIntercept]
        Task<ApiResult<bool>> DeleteById(List<int> ids);

2. redis-based caching

Redis can be used when the access frequency is relatively high, the data is not often modified, but you need other microservices to share the call.Caching is done, as in the case of getting theToken, you need to turn on redis cache interception, you can add on the add, modify the code: Mode = , the following figure:

 

        [ServiceCacheIntercept(, Key = "GetProductStatistics", CacheSectionType = "ddlCache", EnableL2Cache = false, Mode = , Time = 1, EnableStageCache = true)]
        Task<ApiResult<ProductStatisticsModel>> GetProductStatistics();

 

3. L2 Cache

Access frequency is relatively high, the data will be frequently modified, Value data set is very large resulting in bandwidth consumption, this time the use of the second level of caching is the most appropriate, because the large set of data will be read through the second level of local caching, the first level of caching to store flags to manage the invalidation of the second level of caching, the code is as follows

        [(, Key = "GetUserId_{0}", CacheSectionType = "ddlCache", L2Key= "GetUserId_{0}",  EnableL2Cache = true, Mode = , Time = 480,EnableStageCache =true)]

4. Cache middleware sharding

Cache middleware uses a hash-consistent load diversion algorithm so that different KEYs can be dispersed to different service nodes, but also to ensure that the hot spot KEYs centralized access to the problem, you can add the redis service node in the cacheSettings configuration file, the configuration file code is as follows:

{
  "CachingSettings": [
    {
      "Id": "ddlCache",
      "Class": ",",
      "InitMethod": "",
      "Maps": null,
      "Properties": [
        {
          "Name": "appRuleFile",
          "Ref": "rule",
          "Value": "",
          "Maps": null
        },
        {
          "Name": "dataContextPool",
          "Ref": "ddls_sample",
          "Value": "",
          "Maps": [
            {
              "Name": "Redis",
              "Properties": [
                {
                  "Name": null,
                  "Ref": null,
                  "Value": "127.0.0.1:6379::1",
                  "Maps": null
                },
                {
                  "Name": null,
                  "Ref": null,
                  "Value": "127.0.0.1:6379::1",
                  "Maps": null
                },
                {
                  "Name": null,
                  "Ref": null,
                  "Value": "127.0.0.1:6379::1",
                  "Maps": null
                }
              ]
            },
            {
              "Name": "MemoryCache",
              "Properties": null
            }
          ]
        },
        {
          "Name": "defaultExpireTime",
          "Ref": "",
          "Value": "120",
          "Maps": null
        },
        {
          "Name": "connectTimeout",
          "Ref": "",
          "Value": "120",
          "Maps": null
        },
        {
          "Name": "minSize",
          "Ref": "",
          "Value": "1",
          "Maps": null
        },
        {
          "Name": "maxSize",
          "Ref": "",
          "Value": "10",
          "Maps": null
        }
      ]
    },
    {
      "Id": "userCache",
      "Class": ",",
      "InitMethod": "",
      "Maps": null,
      "Properties": [
        {
          "Name": "appRuleFile",
          "Ref": "rule",
          "Value": "",
          "Maps": null
        },
        {
          "Name": "dataContextPool",
          "Ref": "ddls_sample",
          "Value": "",
          "Maps": [
            {
              "Name": "Redis",
              "Properties": [
                {
                  "Name": null,
                  "Ref": null,
                  "Value": "127.0.0.1:7000::1",
                  "Maps": null
                },
                {
                  "Name": null,
                  "Ref": null,
                  "Value": "127.0.0.1:7005::1",
                  "Maps": null
                },
                {
                  "Name": null,
                  "Ref": null,
                  "Value": "127.0.0.1:6379::1",
                  "Maps": null
                }
              ]
            },
            {
              "Name": "MemoryCache",
              "Properties": null
            }
          ]
        },
        {
          "Name": "defaultExpireTime",
          "Ref": "",
          "Value": "120",
          "Maps": null
        },
        {
          "Name": "connectTimeout",
          "Ref": "",
          "Value": "120",
          "Maps": null
        },
        {
          "Name": "minSize",
          "Ref": "",
          "Value": "1",
          "Maps": null
        },
        {
          "Name": "maxSize",
          "Ref": "",
          "Value": "10",
          "Maps": null
        }
      ]
    }
  ]
}

IV. Summary

Wooden boat platform api, ui has been open source release, behind the successive updates, such as the completion of the mqtt and GB 28181 device access, will build the official website and DEMO, please look forward to.