GithubHelp home page GithubHelp logo

hotdetect's Introduction

自动探测热点

  • 一个自动探测热点的SDK【本地探测】
  • 接口埋点统计,埋点对象可以是数字、string等,一般是被访问对象id
  • 通过滑动窗口+频率计数+优先队列计算Top-K,K由业务方参数决定
  • 通过业务回调定时回传上一次窗口热点ID TOP-K,窗口时间由业务方参数决定

可以用于解决高并发下的热点问题。

项目简介

SDK原理图

  • 基于SDK自动探测出热点ID
  • 将热点ID上报,或者将对应数据缓存到本地
  • 接口优先从本地缓存读取数据,miss才从下游存储中获取
  • 这样热点数据大部分会在缓存中被命中,也就解决了热点问题

基础理论模型、实践样例、衍生问题等可参考下面【资料】。

代码示例

创建一个热点探测实例:

import "hotDetect"

func callback((list []hotDetect.TopItem)) {
    // hotDetect会将top-k的热点通过该回调定时传回来
    // 在该回调中处理热点ID,业务可以将热点数据缓存到本地内存,或自行上报
}

detectSomeThing := hotDetect.NewDetect(hotDetect.NewConfig(windowSize int, // 窗口数量
                                                        slidingTime int, // 窗口保持时间
                                                        limitItem int64, // 窗口探测数量上限,预防极端情况
                                                        id string,   // 自定义标识, 日志/埋点上报用
	                                                    sampling int, // 采样率
	                                                    callback, // 回调
                                                        topNum int) // top-k  k的设置

//也可以用默认配置 hotDetect.NewDetect(hotDetect.DefualtConf("someID", callback))

埋点统计:

detectSomeThing.Record(某id)

资料

高并发下的热点处理实践

hotdetect's People

Contributors

earlyzhao avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.