varnamproject / varnamd

Varnam daemon which also acts as a HTTP server. Deprecated. See https://github.com/varnamproject/varnamd-govarnam/
MIT License
8 stars 8 forks source link

Cache requests to skip database query #20

Closed subins2000 closed 3 years ago

subins2000 commented 4 years ago

Performance can be improved if requests to /tl and /rtl is cached to avoid hitting database for fetching result. For a public API server setup, what would be the nice way to do this ?

cc @athul @joicemjoseph

joicemjoseph commented 4 years ago

This is pretty straight forward. We can do it. Should I create a new PR or update existing one ?

subins2000 commented 4 years ago

@joicemjoseph What would be the best way to do this ? I don't know Go much, but from a general POV, I was thinking maybe create a local HashMap on runtime that store frequent words with hitcount. The low hit words in the map gets removed every now and then (interval, perhaps a day)

joicemjoseph commented 4 years ago

I tried to write a echo middleware and failed. Initially I thought it is simple and straight forward, but it was not. As per our implementation, varnamc and varnamd resides in same machine. and both querying and cache lookup will cost almost same. So, I think can be marked as low priority. (sorry for the late reply)

subins2000 commented 4 years ago

@joicemjoseph What's the challenge in the cache part ? From seeing the code, I infer it will now take 100MB RAM for the cache part. I think it's enough. A further enhancement would be clearing cache at intervals according to hit measurement, but let's have that later.

Thank you for your contributions and insights :)

joicemjoseph commented 4 years ago

Clearing cache, etc are managed.

joicemjoseph commented 4 years ago

What's the challenge in the cache part ?

As I mentioned, I tried to add cache on echo. as a middleware. This implementation is caching on handler. That is the difference. It was hard to do in echo (OR I don't know how to do)