Code Monkey home page Code Monkey logo

hotspotter's Introduction

Hotspotter

Hotspotter is a microservice that receives keys that have been requested over time and stores counters using Redis.

Counters are stored in buckets for each hour, as a Redis sorted set (zset), and are aggregated upon request. Aggregation results are cached for a configurable time (default is 2 minutes) so that requests can be handled more efficiently. Given that this service is intended to be consumed from a load balancer, this cache should be tuned according to the expected responsiveness of the system to new hot keys.

Setup and run Redis

See Documentation

Make redis from sources

wget http://download.redis.io/redis-stable.tar.gz
tar xvzf redis-stable.tar.gz
cd redis-stable
make

Run a standalone local redis server

Just execute the "redis-server" script on the src:

redis-stable/src/redis-server

Run application

You can run the application on the default (dev) environment by executing:

sbt run

To specify another enviroment (such as prod), use the following command:

sbt '; set javaOptions += "-Denvironment=prod"; run'

The application will run on port 9290 by default.

Application Resources

Key Hits

You can post several key hits at a time:

POST /key-hits

with a body that follows the structure:

{
	"hits": [
		{ "key": "1234" },
		{ "key": "5678" }
	]
}

You call this service as "fire and forget". The keys will be processed asynchronously.

List key hotspots

You can retrieve a list of the hotspots of the previous H hours (H is configurable):

GET /hotspots

The response will contain a list of the top N keys (N is configurable) sorted by request count descending:

{
	"keys": ["1234", "5678", "..."]
}

Check if a given key is a hotspot

GET /hotspots/:key

Response if the key is a hotspot

Status: 204 No Content

Response if the key is not a hotspot

Status: 404 Not Found

Future Work

  • Local cache of last hotspots to respond in case of a failure on Redis cluster
  • Store a local oplog file and recover from it in case of a failure writing the keys to Redis.
  • Performance/Stress tests using Gatling.
  • Enable configuration of custom buckets instead of fixed hour buckets.
  • Add a way to post summarized hit counts instead of having to repeat the keys.
  • Figure out how to get rid of the annoying security pop-ups when running the tests with the embedded Redis.

hotspotter's People

Contributors

avinocur avatar

Watchers

 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.