GithubHelp home page GithubHelp logo

Comments (3)

coleifer avatar coleifer commented on August 18, 2024

not found for a few seconds.

So it shows up, just slowly?

Can you tell me a bit about how you're deploying Redis? And what the model definition / secondary indexes are doing?

from walrus.

luisdemarchi avatar luisdemarchi commented on August 18, 2024

@coleifer I have a class called "Presence" that needs to be queried and changed in a matter of seconds.

I noticed 2 "big" problems:

  1. When I am changing the status of a record (type of negotiating conversation to initiating conversation), I have a loop in a worker that checks if the two users are still active and if it is not, it interrupts the connection. It turns out that at the time of changing the status does not return the object in the worker's query and he understands that the person "died". But this takes 1 or 2 seconds, so it affects 2 or 3 calls every 10 attempts.

  2. Another problem is that there is a type of a cache in the information. I change the status and then I search the old status and continue bringing the modified object. A few seconds later the searches work correctly.


I made the comment in 2 steps, in the code itself.

class Presence(walrus.Model):
    __database__ = redis_db
    channel_name = walrus.TextField(primary_key=True)
    user = walrus.UUIDField(index=True, default='00000000-0000-0000-0000-000000000000')
    last_seen = walrus.DateTimeField(default=datetime.datetime.now, index=True)
    is_accessible = walrus.IntegerField(index=True, default=0)

    connection_user = walrus.UUIDField(index=True, default='00000000-0000-0000-0000-000000000000')
    connection_state = walrus.IntegerField(default=4, index=True)
    connection_update = walrus.DateTimeField(default=datetime.datetime.now, index=True)


def seeking_connection(presence):
    try:
        query = (Presence.is_accessible == 1) \
            & (Presence.connection_state == 4) \
            & (Presence.user != presence.user)
        presences = Presence.query(query)
        user_selected = random.choice(list(presences))

###See that the query has exactly the IF below, it was necessary to make an IF to reinforce the query because it is up to the query to deliver old data.
        if user_selected.is_accessible != 1 or user_selected.connection_state != 4:
            print("Query did not work")
            return
    except Exception:
        return

   
    presence.is_accessible = 1
    presence.connection_state = 1
    presence.connection_user = user_selected.user
    presence.save()

    user_selected.connection_state = 1
    user_selected.connection_user = presence.user
    user_selected.save()

###Second step I just did to validate, also returns old values.
##From the query I made until I got here, those variables should be right. But the error of not finding the object is intermittent (it's type 2 or 3 times for every 10 queries)
    try:
        Presence.get((Presence.user == presence.connection_user)
                       & (Presence.connection_state != 4)
                       & (Presence.is_accessible == 1))
    except Exception as exeption:
         raise NotFound

from walrus.

coleifer avatar coleifer commented on August 18, 2024

I'm not positive what could be causing you to receive inconsistent results. Since Redis server is single-threaded I would have assumed that your operations would proceed synchronously, i.e., if you call save() the redis client will block until it's finished all operations...and save() can incur quite a few operations. Are you deploying Redis in some kind of multi-server/replicated environment? Is the Redis client returning from executing commands before they've actually been processed?

from walrus.

Related Issues (20)

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.