Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Low performance sending low latency messages between actors #53

Open
jonatelo opened this issue May 24, 2018 · 0 comments
Open

Low performance sending low latency messages between actors #53

jonatelo opened this issue May 24, 2018 · 0 comments

Comments

@jonatelo
Copy link

jonatelo commented May 24, 2018

I using Thespian to develop an application to consume low latency data via sockets. I had created initially two actors: one consumer (socket client connection) and the handler. Testing, I detected some delays between the time used to send one message in the consumer (Actor1) and when this message has arrived in the handler (Actor2).

About message delivery in documentation.

To test that, I had used the following code.

from thespian.actors import ActorSystem, Actor
import time


class Actor1(Actor):
    def receiveMessage(self, handler, sender):
        # benchmark
        data = {'tic': time.perf_counter(), 'lim': 10000}
        print('Elapsed Time to process {} messages'.format(data['lim']))
        for i in range(data['lim']):
            self.send(handler, data)
        # perf
        toc = time.perf_counter() - data['tic']
        print('Actor 1: {} sec'.format(round(toc, 3)))
        # self.actorSystemShutdown()


class Actor2(Actor):
    def __init__(self):
        self.msg_count = 0

    def receiveMessage(self, data, sender):
        self.msg_count += 1
        if self.msg_count == data['lim']:
            toc = time.perf_counter() - data['tic']
            print('Actor 2: {} sec'.format(round(toc, 3)))

def main():
    asys = ActorSystem('multiprocTCPBase')
    consumer = asys.createActor(Actor1)
    handler = asys.createActor(Actor2)
    asys.tell(consumer, handler)

if __name__ == '__main__':
    main()

Results:

Elapsed Time to process 10 messages
Actor 1: 0.002 sec
Actor 2: 0.008 sec

Elapsed Time to process 100 messages
Actor 1: 0.019 sec
Actor 2: 0.099 sec

Elapsed Time to process 1000 messages
Actor 1: 0.131 sec
Actor 2: 0.769 sec

Elapsed Time to process 10000 messages
Actor 1: 1.219 sec
Actor 2: 7.608 sec

Elapsed Time to process 100000 messages
Actor 1: 22.012 sec
Actor 2: 91.419 sec

Looking these results, There is something wrong or missing that I have in my code?, or there is another faster way to send the messages between actors? Also, there is any other benchmark that help us to analyze the performance commented in the documentation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant