Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
  • 07:46
    Aaronontheweb synchronize #4086
  • 07:45
    Aaronontheweb commented #3887
  • 07:44

    Aaronontheweb on dev

    close #4087 - enable akka.clust… (compare)

  • 07:44
    Aaronontheweb closed #4088
  • 07:44
    Aaronontheweb closed #4087
  • 06:34
    Aaronontheweb labeled #4083
  • 06:33
    Aaronontheweb labeled #4083
  • 06:33
    Aaronontheweb milestoned #4083
  • 06:31
    Aaronontheweb opened #4088
  • 06:31
    Aaronontheweb labeled #4088
  • 06:31
    Aaronontheweb labeled #4088
  • 06:19
    Aaronontheweb commented #4087
  • 06:19
    Aaronontheweb milestoned #4087
  • 06:19
    Aaronontheweb labeled #4087
  • 06:19
    Aaronontheweb labeled #4087
  • 06:18
    Aaronontheweb opened #4087
  • 06:13
    Aaronontheweb commented #4086
  • Dec 09 20:47
    IgorFedchenko commented #4085
  • Dec 09 20:46
    IgorFedchenko commented #4085
  • Dec 09 15:09
    IgorFedchenko commented #4085
Jay DeBoer
@jaydeboer
@Danthar Thanks, I was reading the docs, other docs, that were not as clear. Thanks for that link, that really helped explain it. :)
mikeprag
@mikeprag
Hi All...I have implemented Akka.NET in a dispatcher / worker pattern to distribute load across multiple machines for a job processing system. On the remote machines I have a service running with Akka workers waiting to accept remote requests. When the worker (actor) is created, it instantiates a type using Assembly.LoadFrom - the location to load the dll is passed as part of the worker creation request. Then, requests to process an xml data file are sent to the worker actors which should use the assembly that was instantiated when the worker was created to process the data. My main dispatcher works with batches of data (a job) and in between jobs, stops the remote workers. When a new job is created, it creates new workers to process the job. This is working fine however on subsequent jobs, where the source .dll has changed, it seems that the old .dll is being used instead of the new one. On each new job, the dispatcher first pulls the assets (dll and other files) to a new file share where the worker should load it from and I can see from my logs that the new worker is using the correct location however the results are showing its using the .dll from a previous job (worker). I am creating my actors with a unique name and I thought this would give some isolation as new, unique workers would be created. What am I missing that the remote process is re-using workers or the .dll. I know something is not quite right as the remote service has a lock on the .dll even after its finished and the workers have been stopped as when I come to delete the assets in the shared folder, I'm unable to until I shut down the remote service. Sorry for the long winded description - Any ideas?
Stijn Herreman
@stijnherreman
@mikeprag You cannot unload an assembly once it's been loaded, nor can you reload it. You need to create a new AppDomain if you want to do that.
mikeprag
@mikeprag
Hi Stijn....Thanks for the quick response....I thought (clearly incorrectly) that multiple actors would have separate AppDomains but I guess this is not the case. Is there anyway in the Akka config to have workers created in separate AppDomains so I can 'config' out this issue or do I need to write this into my worker?
Stijn Herreman
@stijnherreman
I think this is something you need to write yourself, but I'm not sure. Others with more experience might be able to confirm that.
mikeprag
@mikeprag
@stijnherreman - Thanks. I guess it wouldn't be too hard to create an AppDomain to execute on. Is this just a general issue / thing to bear in mind with Akka that if you change any of the binaries for execution, you would have to restart the remote host process every time? Does anyone know of a way to do this from Akka config? Is this something to do with the Akka dispatcher?
Vagif Abilov
@object
@mikeprag It doesn't sound like running actors in separate AppDomains fit well actors nature. Actors have very small footprint (few hundred bytes), they don't have allocated threads, they just borrow threads to process messages. AFAIK an AppDomain drags a memory footprint of at megabytes, not even kilobytes (didn't find any figures but will be very surprised if it's below 1 meg). This shouldn't stop you from creating additional domains, but I think you need to do it outside actor system.
PinkyBrain
@PinkyBrain_gitlab
what's the right pattern for implementing throttling functionality with actors? I would like to have an actor receive a message with a collection of things to process, and it would create a new actor to process each one, and it should be able to limit the number of outstanding operations (child actors who have not replied yet)
if I understand correctly the one message at a time promise, once this actor receives the message with the collection of items to process and starts creating child actors, how will it know that one of these child actors has replied, if it can't process that reply message until it's finished processing the one with the collection of items?
would I need to use pipeTo? would it be safe to have a mutable property in that parent actor keeping track of the number of outstanding child actors, or can I get this from akka itself?
v1rusw0rm
@v1rusw0rm
@PinkyBrain_gitlab seems like Router is what you need: https://getakka.net/articles/actors/routers.html
AndreSteenbergen
@AndreSteenbergen
@PinkyBrain_gitlab you could create some sort of aggregator, with a HashSet of actors wich are still active. On a received message you remove the actor from the set, and give any outstanding work to a new actor. You can decide if you want to collect all data before returning to the original sender, or pass along directly. You could start this intermediary actor with a deathwatch. If no outstanding work is present, and the activeHashSet is empty you could killl off the actor; this way the originalSender knows when you are done procesing.
You do need to know what actortype to start foreach message, so you could create the intermedate actor with a Dictionary<Type, Type> (message => actor), and off course a number how big the active set (concurrency may be e.g. 50); When all messages are processed, simply return all results if not already done, and die
PinkyBrain
@PinkyBrain_gitlab
@v1rusw0rm so from reading that, seems I would go for a pool roundrobin router, right? The operation that each routee would perform is async, does this mean I have to force it to run async, otherwise that routee will start processing the next message in its queue and I lose the throttling effect of the router
Does that sound like the way to go?
AndreSteenbergen
@AndreSteenbergen
This function send 1 message to a very large set of actors; I had issues sending out too many messages at once, so I created a throttler, it doesn't do exactly what you need, but it can give you a start.
public class ThrottledMessenger : ReceiveActor
{
    private int workerPool;
    private readonly Queue<IActorRef> waitingActors;
    private IActorRef originalSender;
    private object originalMessage;

    public ThrottledMessenger(int parallelWorkers, IEnumerable<IActorRef> refs)
    {
        waitingActors = new Queue<IActorRef>(refs.Skip(parallelWorkers));

        ReceiveAny(x =>
        {
            originalSender = Sender;
            originalMessage = x;

            foreach (var aref in refs.Take(parallelWorkers))
            {
                workerPool++;
                aref.Tell(x);
            }
            Become(Messenging);
        });
    }

    private void Messenging()
    {
        ReceiveAny(msg =>
        {
            workerPool--;
            originalSender.Tell(msg, Sender);
            if (waitingActors.TryDequeue(out IActorRef nextActor))
            {
                workerPool++;
                nextActor.Tell(originalMessage);                    
            }
            else if (workerPool == 0)
            {
                Context.Stop(Self);
            }
        });
    }
}
BTW this only works when the actor responds with a Sender.Tell( stuff ) after it's done.
PinkyBrain
@PinkyBrain_gitlab
@AndreSteenbergen Yea that's what I need anyway, give me 5minutes to understand what you're doing there
AndreSteenbergen
@AndreSteenbergen
I can walk you through to code, if you want
It basically sends the parallel amount I have choosen a single message (.Take(parallelworkers))
all other messages are enqueued
PinkyBrain
@PinkyBrain_gitlab
Sure, so I would need to create a pool of actors as large as the batch of messages I want to process beforehand right?
AndreSteenbergen
@AndreSteenbergen
Do you know the actor type for the messages?
PinkyBrain
@PinkyBrain_gitlab
yes
AndreSteenbergen
@AndreSteenbergen
is it just 1?
actor type
PinkyBrain
@PinkyBrain_gitlab
yes
AndreSteenbergen
@AndreSteenbergen
You can create the numbers of actors up front, as large as your pool - better yet: just create them when you receive the messages to process
everytime a message comes back, you can hand it one of the messages from your queue
I guess it isn't actually a lot different from this code, you would give it IEnumerable<object>, instead of IActorf ref
the ctor can be, int numberOfWorkers, and a method to create the actor (Props)
the initial receive would be the IEnumerable<object> (your message), you create your batch of actors in the Receive
enqueue all messages you can't process yet
and change state in Receiving using Become
AndreSteenbergen
@AndreSteenbergen
every time you receive something, you can send the parent actor the result, and give the actor which gave the result a message
when done, kill off the actr
ReceiveAny in the constructor would be Receive<ObjectHoldingAllMessagesToProcess>
I hope I make sense
AndreSteenbergen
@AndreSteenbergen
The actor creating this intermediate actor Watch it using intermediate.WatchWith(new DoneProcessingLotsOfMessages()), which will raise DoneProcessingLotsOfMessages
PinkyBrain
@PinkyBrain_gitlab
How about this: the throttledmessenger receives a message with the batch, it would first put the items in the batch into a queue, then dequeue parallelWorkers many items and create an actor for each and Tell them those items, then become a new state, where on each message received it Dequeues another item, creates another actor, and sends it that item, until the queue is empty
then I dont need to keep track of the workerPool or create all my actors up front
AndreSteenbergen
@AndreSteenbergen
That's what I meant with my first line ;) better yet: just create them when you receive the messages to process
Yuo don't need to create a new actor
the actor which processed the previous messages, can process a new one
PinkyBrain
@PinkyBrain_gitlab
the throttledmessenger can compile the results of all its children, so I would have just one originalSender.Tell in the case where the queue is empty, right? so the actor that wants the batch processed sends ThrottledMessenger an Ask, would that work?
ah right, so I would have at most parallelWorkers actors
AndreSteenbergen
@AndreSteenbergen
Yes, that would work
PinkyBrain
@PinkyBrain_gitlab
This sounds like an implementation of the roundrobin router :P