简体   繁体   English

Akka是否根据可用资源来规范参与者?

[英]Does Akka regulate actors based on available resources?

I have a set of database documents (a few thousand) for which I would like to run some data migration activities. 我有一组数据库文档(几千个),我想为其运行一些数据迁移活动。 Each of these documents holds a reference to a different file in a Windows filesystem. 这些文档中的每一个都包含对Windows文件系统中不同文件的引用。 These files are stored in a file server that is accessed through a shared folder. 这些文件存储在通过共享文件夹访问的文件服务器中。 What I would like to do is to move the files to a different location in the filesystem, rearranging them based on properties in the documents. 我想做的是将文件移动到文件系统中的其他位置,然后根据文档中的属性重新排列它们。

I have thought of the following design: 我想到了以下设计:

  1. Have one actor that queries the database and that spawns one actor per document 拥有一个查询数据库的参与者,并且每个文档产生一个参与者
  2. Each of these actors would be responsible for copying their related file to its new location, and of handling any exceptions 这些参与者中的每一个都将负责将其相关文件复制到新位置,并负责处理任何例外情况。
  3. When each of these actors finishes its task, it will inform a central actor of the outcome (success / failure) 当每个参与者完成任务时,它将把结果(成功/失败)通知中心参与者。

Is this a naïve design? 这是幼稚的设计吗? Should I throttle how many actors are created, or does Akka regulate the assigned resources based on processor availability? 我应该限制创建的角色多少,还是Akka根据处理器的可用性调节分配的资源? Could there be any problems on the filesystem side, having too many requests active simultaneously? 文件系统方面是否存在任何问题,同时有太多请求处于活动状态?

The default thread pool/execution context/dispatcher of akka will have one something like one thread per core, moving files is probably a blocking operation so you will only have as many files moved at any given moment as you have cores and during that time no other actor will be invoked. akka的默认线程池/执行上下文/调度程序每个内核都有一个线程,移动文件可能是一项阻塞操作,因此在给定的任何时刻,您移动的文件数仅与拥有内核的一样多,在此期间,其他角色将被调用。

You could configure the dispatcher to use more threads to get more parallell activity, or put the file moving actors to a specific dispatcher that does not interfer with the other actors. 您可以将调度程序配置为使用更多线程来获取更多的并行活动,或者将文件移动actor放置到不干扰其他actor的特定调度程序中。

Maybe a better idea would be to see the documents as the messages passing through your system, in one end you enumerate each document as a message, send it to an actor that parses the properties from the files and forward that to an actor that does the actual moving. 也许更好的主意是将文档视为通过系统传递的消息,最后,您将每个文档枚举为一条消息,将其发送给actor,该actor解析文件中的属性,然后将其转发给执行此操作的actor。实际移动。 This makes it possible to decide how many parser-actor instances and how many mover-actor instances depending on the throughput of your disks etc. 这样就可以根据磁盘的吞吐量等来决定有多少个解析器-actor实例和多少个move-actor实例。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM