Hi Andrey,

You can increment in uwsgi cache (which takes string keys):
http://uwsgi-docs.readthedocs.org/en/latest/Changelog-1.9.9.html#math-for-cache

Or you can use pylmdb which is a very fast embedded db.

On Wed, May 20, 2015 at 2:50 PM, Andrey Shmigelsky <[email protected]
> wrote:

> I'm trying to improve my application performance and want to get ride of
> unnecessary requests to database. I have couple of counters that I can
> allow to be stored temporary. Currently, my implementation works well but
> can't be scaled, that is why I need another solution.
>
> So to the problem:
>
> 1. I receive requests with JSON data from which I create ID for redis like
> "prefix:USA:123122"
> 2. Instead of going to that key in Redis, I want to go straight to shared
> memory and increment the value. To do it, I need to know the position. I do
> md5 hashing to that key, which gives me in that
> case 569b6f34b5275a30c7b69a6be69cb306
> 3. Take first 7 characters of that md5 and convert it to decimal which
> gives me 90814195
> 4. I do uwsgi.sharedarea_inc32(0, 90814195)
> 5. And where I need to know the value I do uwsgi.sharedarea_read32(0,
> 90814195)
>
> The problem is that first seven characters is not enough, I start to see
> duplicate first seven characters of md5 on different keys but I can't give
> more memory to shared area and use 8 chars.
>
> So I thought is there a way to create a simple key value db inside shared
> area, read it on every request, update the counter and put it back.
> Something like pickle python dictionary to shared memory and fill other
> space with zeros. The problem with such approach is that increments are not
> atomic.
>
> Is uWSGI already provide something to solve my problem?
>
>
> _______________________________________________
> uWSGI mailing list
> [email protected]
> http://lists.unbit.it/cgi-bin/mailman/listinfo/uwsgi
>
>
_______________________________________________
uWSGI mailing list
[email protected]
http://lists.unbit.it/cgi-bin/mailman/listinfo/uwsgi

Reply via email to