Regarding Actor event loops working

31 views
Skip to first unread message

Aditya Nugur

unread,
Jul 20, 2017, 5:35:25 PM7/20/17
to python-pulsar


Hi all,

I am new to the asyncio library and have been reading documentation since past few weeks but I still feel I am not 100% aware of how it works. I am developing a simple back-end gateway application, which receives a request from the remote client and makes communication with local devices in the gateway network. I feel pulsar actor model perfectly suits my need. I have been working on the architecture and I am not sure if I am going in the right direction. Can any one please clarify by answering some of my questions so that I have a better understanding of the library-

1) I want my software to be stable, so I was planning to start with 2 loops/threads as the beginning of software, one which starts the arbiter and the other which monitors arbiter by calling is_alive() method and restarts the arbiter if at all its false? Is this a right approach?

2) I have different devices of different protocols, I would like to have 3 Application classes (or monitors as mentioned in design page) which run in arbiters event loop. One is the web server application class which gets the request and other 2 application classes are to handle the request from the web server. Now each application class has multiple actors such as web server has multiple actors to handle incoming request and remaining 2 application specific classes have its own actors to talk to local devices. Everything sounds good with this architecture but I am confused with following things-

1) say application 1 has 5 actors and is running its event loop and then concurrently application 2 also has 5 actors in its event loop running. During this time is the web server (the other application classes in arbiter event loop) running to receive any requests from clients?? Or will the software be busy running application's event loop and doesn't run any context related to the Arbiters/web server's event? I have read about event loop paradigm but since this is an event loop within an event loop, I am not sure how it works. Can anyone please clarify?
1) Also, I found a class called actorproxymonitor. Is it similar to application class( or monitor as mentioned in design page)?

2) Is there an OOP way to interface application/monitor or arbiter with its actors because I would have an opportunity to save states and pass on variables? I looked into remote.py example but that doesn't help. It has an application class called calculator which didn't inherit any application class or actor class or actorproxymonitor class. It inherited the remote class and I'm not sure how it links with concurrency class. If anyone would refer me to any big/medium or small project where pulsar is implemented it would be great for me to get the hang of it. 

3) Let's say I have my applications(arbiter event loop) is up and running. Once each of my application loop starts, each application spawns actors to talk to local devices, I want to periodically talk to the devices so I spawned actors with a periodic_task hook having the methods to talk to the device. Since the communication with all devices takes long time and since this actor is interfaced with 3rd party protocol libraries I couldn't give explicit yield (because they don't return futures) But interestingly, the control is returned back to the application event loop to run other actors when ever it gets blocked (I don't know how but I read asyncio doesn't support implicit yield). So far so good but looks like the same periodic_task hooked function also sends notify to the arbiter. Since it's blocked after a while, arbiter kills the actor. Is there a work around for this like sending notify separately? I was thinking of inheriting actor class and override variable "next_periodic_task" with my task in it? Can anyone suggest?

4) Also, I wanted to have control over the time interval for "periodic_task". I see it is set from various parameters like max_notify, min_notify,monitor/arbiter event loop config.settings['timeout']variable. Can any one suggest changing which variable would be best to play around with in order to just change periodic task time interval and nothing else?

5) Lastly, As I want to have my system robust, I was thinking if its possible to spawn any actor if it's stopped by adding a method to the stopping hook where it notifies to some monitor to respawn the killed actor. Is it possible? 


I am sorry for so many questions. I just want to have my basics right before implementing the project. Thank you so much for the help. It would be great even if someone guides me to some Pulsar project implementations so that I get deeper insights.

Thanks,
Aditya

 
Reply all
Reply to author
Forward
0 new messages