- 配置
- This is the reference config file that contains all the default settings.
- Make your edits/overrides in your application.conf.
- Initial contact points of the cluster.
- The nodes to join automatically at startup.
- Comma separated full URIs defined by a string on the form of
- "akka.tcp://system@hostname:port"
- Leave as empty if the node is supposed to be joined manually.
- how long to wait for one of the seed nodes to reply to initial join request
- If a join request fails it will be retried after this period.
- Disable join retry by specifying "off".
- Should the 'leader' in the cluster be allowed to automatically mark
- unreachable nodes as DOWN after a configured time of unreachability?
- Using auto-down implies that two separate clusters will automatically be
- formed in case of network partition.
- Disable with "off" or specify a duration to enable auto-down.
- deprecated in 2.3, use 'auto-down-unreachable-after' instead
- The roles of this member. List of strings, e.g. roles = ["A", "B"].
- The roles are part of the membership information and can be used by
- routers or other services to distribute work to certain member types,
- e.g. front-end and back-end nodes.
- Minimum required number of members of a certain role before the leader
- changes member status of 'Joining' members to 'Up'. Typically used together
- with 'Cluster.registerOnMemberUp' to defer some action, such as starting
- actors, until the cluster has reached a certain size.
- E.g. to require 2 nodes with role 'frontend' and 3 nodes with role 'backend':
- frontend.min-nr-of-members = 2
- backend.min-nr-of-members = 3
- <role-name>.mi
配置
你开始使用Akka时可以不需要定义任何配置,因为Akka提供了合理的默认值。不过为了适应特定的运行环境,你可能需要修改设置来更改默认行为。可以修改的典型设置的例子:
- 日志级别和后端记录器
- 启用远程
- 消息序列化
- 路由器定义
- 调度的调整
Akka使用Typesafe配置库,它同样也是你自己的应用或库的不错选择,不管你用不用Akka。这个库由Java实现,没有外部的依赖;本文后面将只对这个库有一些归纳,你应该查看其文档参考具体的使用(尤其是ConfigFactory)。
警告
如果你在Scala REPL的2.9.x系列版本中使用Akka,并且你不提供自己的ClassLoader给ActorSystem,则需要以“-Yrepl-sync”选项启动REPL来解决上下文ClassLoader的缺陷。
配置读取的地方
Akka的所有配置都保存在ActorSystem的实例中,或者换一种说法,从外界来看,ActorSystem是配置信息的唯一消费者。在构造一个actor系统时,你可以选择传进一个Config对象,如果不传则等效于传入ConfigFactory.load()(通过正确的类加载器)。粗略的讲,这意味着默认会解析classpath根目录下所有的application.conf,application.json和application.properties文件——请参考前面提到的文档以获取细节。然后actor系统会合并classpath根目录下的所有 reference.conf行成后备配置,也就是说,它在内部使用
1. appConfig.withFallback(ConfigFactory.defaultReference(classLoader))
其哲学是代码永远不包含缺省值,相反是依赖于随库提供的 reference.conf 中的配置。
系统属性中覆盖的配置具有最高优先级,参见HOCON 规范(靠近末尾的位置)。此外值得注意的是,应用程序配置——缺省为application——可以使用config.resource属性重写 (还有更多,请参阅配置文档)。
注意
如果你正在编写一个Akka 应用,将你的配置保存类路径的根目录下的
application.conf文件中。如果你正在编写一个基于Akka的库,将其配置保存在JAR包根目录下的reference.conf文件中。
当使用JarJar,,OneJar,Assembly或任何jar打包命令(jar-bundler)
警告
Akka的配置方法重度依赖于这个理念——每一模块/jar都有它自己的
reference.conf文件,所有这些都将会被配置发现并加载。不幸的是,这也意味着如果你放置/合并多个jar到相同的 jar中,你也需要合并所有的reference.conf文件。否则所有的默认设置将会丢失,Akka将无法工作。
如果你使用 Maven 打包应用程序,你还可以使用Apache Maven Shade Plugin中对资源转换(Resource
Transformers)的支持,来将所有构建类路径中的reference.conf合并为一个文件。
插件配置可能如下所示:
1. <plugin>
2. <groupId>org.apache.maven.plugins</groupId>
3. <artifactId>maven-shade-plugin</artifactId>
4. <version>1.5</version>
5. <executions>
6. <execution>
7. <phase>package</phase>
8. <goals>
9. <goal>shade</goal>
10. </goals>
11. <configuration>
12. <shadedArtifactAttached>true</shadedArtifactAttached>
13. <shadedClassifierName>allinone</shadedClassifierName>
14. <artifactSet>
15. <includes>
16. <include>*:*</include>
17. </includes>
18. </artifactSet>
19. <transformers>
20. <transformer
21. implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
22. <resource>reference.conf</resource>
23. </transformer>
24. <transformer
25. implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
26. <manifestEntries>
27. <Main-Class>akka.Main</Main-Class>
28. </manifestEntries>
29. </transformer>
30. </transformers>
31. </configuration>
32. </execution>
33. </executions>
34. </plugin>
自定义application.conf
一个自定义的application.conf可能看起来像这样:
1. # In this file you can override any option defined in the reference files.
2. # Copy in parts of the reference files and modify as you please.
4. akka {
6. # Loggers to register at boot time (akka.event.Logging$DefaultLogger logs
7. # to STDOUT)
8. loggers = ["akka.event.slf4j.Slf4jLogger"]
10. # Log level used by the configured loggers (see "loggers") as soon
11. # as they have been started; before that, see "stdout-loglevel"
12. # Options: OFF, ERROR, WARNING, INFO, DEBUG
13. loglevel = "DEBUG"
15. # Log level for the very basic logger activated during ActorSystem startup.
16. # This logger prints the log messages to stdout (System.out).
17. # Options: OFF, ERROR, WARNING, INFO, DEBUG
18. stdout-loglevel = "DEBUG"
20. actor {
21. provider = "akka.cluster.ClusterActorRefProvider"
23. default-dispatcher {
24. # Throughput for default Dispatcher, set to 1 for as fair as possible
25. throughput = 10
26. }
27. }
29. remote {
30. # The port clients should connect to. Default is 2552.
31. netty.tcp.port = 4711
32. }
33. }
包含文件" class="reference-link">包含文件
有时包含另一个配置文件内容的能力是非常有用的,例如假设你有一个application.conf包含所有环境独立设置,然后使用特定环境的设置覆写。
用-Dconfig.resource=/dev.conf制定系统属性,将会加载dev.conf文件,并包含application.conf
dev.conf:
1. include "application"
3. akka {
4. loglevel = "DEBUG"
5. }
更高级的包括和替换机制的解释在HOCON规范中。
配置日志
如果系统或配置属性akka.log-config-on-start 被设置为 on,则在actor系统启动的时候,就完成了INFO级别的日志设置。当你不能确定使用何种配置时,这很有用。
如果有疑问,你也可以在创建actor系统之前或之后,很容易很方便地检查配置对象:
1. Welcome to Scala version @scalaVersion@ (Java HotSpot(TM) 64-Bit Server VM, Java 1.6.0_27).
2. Type in expressions to have them evaluated.
3. Type :help for more information.
5. scala> import com.typesafe.config._
6. import com.typesafe.config._
8. scala> ConfigFactory.parseString("a.b=12")
9. res0: com.typesafe.config.Config = Config(SimpleConfigObject({"a" : {"b" : 12}}))
11. scala> res0.root.render
12. res1: java.lang.String =
13. {
14. # String: 1
15. "a" : {
16. # String: 1
17. "b" : 12
18. }
19. }
展示结果中,每个项目前会有评论展示这个配置的起源(对应的文件和行数),并展示已存在的评论,如配置参考中的。actor系统合并参考并解析后形成的设置,可以这样显示:
1. final ActorSystem system = ActorSystem.create();
2. System.out.println(system.settings());
3. // this is a shortcut for system.settings().config().root().render()
谈一谈类加载器
在配置文件的几个地方,可以通过制定类的全名来让Akka实例化该类。这是通过Java反射完成的,相应地用到了一个ClassLoader。在具有挑战性的环境中,如应用容器和OSGi绑定中,选择正确的类加载器并不总是一件简单的事情,Akka的现行做法是每个 ActorSystem 实现存储当前线程的上下文类加载器(如果可用,否则就使用他自己的加载器this.getClass.getClassLoader),并使用它为所有的反射访问服务。这意味着Akka放在引导类路径(boot class path)下,会从奇怪的地方产生NullPointerException: 这里就是不支持。
应用特定设置
配置也可用于应用程序特定的设置。一个好的实践是将这些设置放在一个扩展中,像下面的章节所描述的:
配置多个ActorSystem
如果你有一个以上的ActorSystem(或你正在写一个库,有可能有一个独立于应用的 ActorSystem) 你可能想要为每个系统进行单独配置。
由于 ConfigFactory.load() 会合并classpath中所有匹配名称的资源, 最简单的方式是利用这一功能并在配置树中区分actor系统:
1. myapp1 {
2. akka.loglevel = "WARNING"
3. my.own.setting = 43
4. }
5. myapp2 {
6. akka.loglevel = "ERROR"
7. app2.setting = "appname"
8. }
9. my.own.setting = 42
10. my.other.setting = "hello"
1. val config = ConfigFactory.load()
2. val app1 = ActorSystem("MyApp1", config.getConfig("myapp1").withFallback(config))
3. val app2 = ActorSystem("MyApp2",
4. config.getConfig("myapp2").withOnlyPath("akka").withFallback(config))
这两个例子演示了“提升子树”技巧的不同变种: 第一种情况下,actor系统获得的配置是
1. akka.loglevel = "WARNING"
2. my.own.setting = 43
3. my.other.setting = "hello"
4. // plus myapp1 and myapp2 subtrees
而在第二种情况下,只有 “akka” 子树被提升了,结果如下:
1. akka.loglevel = "ERROR"
2. my.own.setting = 42
3. my.other.setting = "hello"
4. // plus myapp1 and myapp2 subtrees
注意
这个配置文件库非常强大,这里不可能解释其所有的功能。特别是如何在配置文件中包含其它的配置文件 (在
包含文件Including files中有一个简单的例子) 以及通过路径替换来复制部分配置树。
你也可以在初始化ActorSystem时,通过代码的形式,使用其它方法来指定和解析配置信息。
1. import akka.actor.ActorSystem
2. import com.typesafe.config.ConfigFactory
3. val customConf = ConfigFactory.parseString("""
4. akka.actor.deployment {
5. /my-service {
6. router = round-robin-pool
7. nr-of-instances = 3
8. }
9. }
10. """)
11. // ConfigFactory.load sandwiches customConfig between default reference
12. // config and default overrides, and then resolves it.
13. val system = ActorSystem("MySystem", ConfigFactory.load(customConf))
从自定义位置读取配置
你可以使用代码或系统属性,来替换或补充application.conf 。
如果你使用的方法是ConfigFactory.load()(Akka默认方式),你可以通过定义-Dconfig.resource=whatever、-Dconfig.file=whatever或
-Dconfig.url=whatever替换 application.conf。
在-Dconfig.resource和相关选项指定的替换配置文件中,如果你还想使用application.{conf,json,properties},可以使用include
"application"。在include
"application"之前指定的设置会被包含进来的文件内容重写,同理所包含文件的内容也会被之后的内容重写。
在代码中,有很多自定义选项。
ConfigFactory.load()有几个重载;这些重载允许你指定夹在 系统属性(重写)和默认值(来自reference.conf)之间的配置,并替换通常的application.{conf,json,properties}和-Dconfig.file相关选项。
ConfigFactory.load() 最简单的变体需要资源基本名称(application之外的);如myname.conf、myname.json和myname.properties而不是application.{conf,json,properties}。
最灵活的变体是以一个Config对象为参数,你可以使用ConfigFactory中的任何方法加载。例如,你可以在代码中使用ConfigFactory.parseString()处理一个配置字符串,或者你可以使用ConfigFactory.parseMap()创建一个映射,或者也可以加载一个文件。
你也可以将自定义的配置与通常的配置组合起来,像这样:
1. // make a Config with just your special setting
2. Config myConfig =
3. ConfigFactory.parseString("something=somethingElse");
4. // load the normal config stack (system props,
5. // then application.conf, then reference.conf)
6. Config regularConfig =
7. ConfigFactory.load();
8. // override regular stack with myConfig
9. Config combined =
10. myConfig.withFallback(regularConfig);
11. // put the result in between the overrides
12. // (system props) and defaults again
13. Config complete =
14. ConfigFactory.load(combined);
15. // create ActorSystem
16. ActorSystem system =
17. ActorSystem.create("myname", complete);
使用Config对象时,请牢记这个蛋糕有三”层”:
ConfigFactory.defaultOverrides()(系统属性)- 应用设置
ConfigFactory.defaultReference()(reference.conf)
正常的目标是要自定义中间一层,不管其他两个。
ConfigFactory.load()加载整个堆栈ConfigFactory.load()的重载允许你指定一个不同的中间层ConfigFactory.parse()变体加载单个文件或资源
要叠加两层,可使用override.withFallback(fallback);请努力保持系统属性(defaultOverrides())在顶部,reference.conf (defaultReference())在底部。
要记住,通常你只需要在application.conf添加一个include语句,而不是编写代码。在application.conf顶部引入的将被application.conf其余部分覆盖,而那些在底部的设置将覆盖以前的内容。
Actor部署配置
可以在配置的akka.actor.deployment节中定义特定actor的部署设置。在部署部分有可能定义这些事物——调度器、邮箱、路由器设置和远程部署。在相应主题的章节中详细介绍了配置的这些特性。一个例子,可以如下所示:
1. akka.actor.deployment {
3. # '/user/actorA/actorB' is a remote deployed actor
4. /actorA/actorB {
5. remote = "akka.tcp://sampleActorSystem@127.0.0.1:2553"
6. }
8. # all direct children of '/user/actorC' have a dedicated dispatcher
9. "/actorC/*" {
10. dispatcher = my-dispatcher
11. }
13. # '/user/actorD/actorE' has a special priority mailbox
14. /actorD/actorE {
15. mailbox = prio-mailbox
16. }
18. # '/user/actorF/actorG/actorH' is a random pool
19. /actorF/actorG/actorH {
20. router = random-pool
21. nr-of-instances = 5
22. }
23. }
25. my-dispatcher {
26. fork-join-executor.parallelism-min = 10
27. fork-join-executor.parallelism-max = 10
28. }
29. prio-mailbox {
30. mailbox-type = "a.b.MyPrioMailbox"
31. }
一个指定actor部署部分的设置是通过其相对 /user的路径来标识的。
你可以使用星号作为通配符匹配actor的路径部分,所以你可以指定:/*/sampleActor将匹配该树形结构中那个级别上的所有sampleActor。你也能把通配符放在最后来匹配某一级别的所有actor:/someParent/*。非通配符匹配总是有更高的优先级,所以:/foo/bar比/foo/* 更具体,并且只有最高优先的匹配才会被使用。请注意它不能用于部分匹配,像这样:/foo*/bar、/f*o/bar 等。
参考配置清单
每个Akka模块都有保存默认值的“reference”配置文件。
akka-actor
1. ####################################
2. # Akka Actor Reference Config File #
3. ####################################
5. # This is the reference config file that contains all the default settings.
6. # Make your edits/overrides in your application.conf.
8. akka {
9. # Akka version, checked against the runtime version of Akka.
10. version = "2.3.6"
12. # Home directory of Akka, modules in the deploy directory will be loaded
13. home = ""
15. # Loggers to register at boot time (akka.event.Logging$DefaultLogger logs
16. # to STDOUT)
17. loggers = ["akka.event.Logging$DefaultLogger"]
19. # Loggers are created and registered synchronously during ActorSystem
20. # start-up, and since they are actors, this timeout is used to bound the
21. # waiting time
22. logger-startup-timeout = 5s
24. # Log level used by the configured loggers (see "loggers") as soon
25. # as they have been started; before that, see "stdout-loglevel"
26. # Options: OFF, ERROR, WARNING, INFO, DEBUG
27. loglevel = "INFO"
29. # Log level for the very basic logger activated during ActorSystem startup.
30. # This logger prints the log messages to stdout (System.out).
31. # Options: OFF, ERROR, WARNING, INFO, DEBUG
32. stdout-loglevel = "WARNING"
34. # Log the complete configuration at INFO level when the actor system is started.
35. # This is useful when you are uncertain of what configuration is used.
36. log-config-on-start = off
38. # Log at info level when messages are sent to dead letters.
39. # Possible values:
40. # on: all dead letters are logged
41. # off: no logging of dead letters
42. # n: positive integer, number of dead letters that will be logged
43. log-dead-letters = 10
45. # Possibility to turn off logging of dead letters while the actor system
46. # is shutting down. Logging is only done when enabled by 'log-dead-letters'
47. # setting.
48. log-dead-letters-during-shutdown = on
50. # List FQCN of extensions which shall be loaded at actor system startup.
51. # Should be on the format: 'extensions = ["foo", "bar"]' etc.
52. # See the Akka Documentation for more info about Extensions
53. extensions = []
55. # Toggles whether threads created by this ActorSystem should be daemons or not
56. daemonic = off
58. # JVM shutdown, System.exit(-1), in case of a fatal error,
59. # such as OutOfMemoryError
60. jvm-exit-on-fatal-error = on
62. actor {
64. # FQCN of the ActorRefProvider to be used; the below is the built-in default,
65. # another one is akka.remote.RemoteActorRefProvider in the akka-remote bundle.
66. provider = "akka.actor.LocalActorRefProvider"
68. # The guardian "/user" will use this class to obtain its supervisorStrategy.
69. # It needs to be a subclass of akka.actor.SupervisorStrategyConfigurator.
70. # In addition to the default there is akka.actor.StoppingSupervisorStrategy.
71. guardian-supervisor-strategy = "akka.actor.DefaultSupervisorStrategy"
73. # Timeout for ActorSystem.actorOf
74. creation-timeout = 20s
76. # Frequency with which stopping actors are prodded in case they had to be
77. # removed from their parents
78. reaper-interval = 5s
80. # Serializes and deserializes (non-primitive) messages to ensure immutability,
81. # this is only intended for testing.
82. serialize-messages = off
84. # Serializes and deserializes creators (in Props) to ensure that they can be
85. # sent over the network, this is only intended for testing. Purely local deployments
86. # as marked with deploy.scope == LocalScope are exempt from verification.
87. serialize-creators = off
89. # Timeout for send operations to top-level actors which are in the process
90. # of being started. This is only relevant if using a bounded mailbox or the
91. # CallingThreadDispatcher for a top-level actor.
92. unstarted-push-timeout = 10s
94. typed {
95. # Default timeout for typed actor methods with non-void return type
96. timeout = 5s
97. }
99. # Mapping between ´deployment.router' short names to fully qualified class names
100. router.type-mapping {
101. from-code = "akka.routing.NoRouter"
102. round-robin-pool = "akka.routing.RoundRobinPool"
103. round-robin-group = "akka.routing.RoundRobinGroup"
104. random-pool = "akka.routing.RandomPool"
105. random-group = "akka.routing.RandomGroup"
106. balancing-pool = "akka.routing.BalancingPool"
107. smallest-mailbox-pool = "akka.routing.SmallestMailboxPool"
108. broadcast-pool = "akka.routing.BroadcastPool"
109. broadcast-group = "akka.routing.BroadcastGroup"
110. scatter-gather-pool = "akka.routing.ScatterGatherFirstCompletedPool"
111. scatter-gather-group = "akka.routing.ScatterGatherFirstCompletedGroup"
112. tail-chopping-pool = "akka.routing.TailChoppingPool"
113. tail-chopping-group = "akka.routing.TailChoppingGroup"
114. consistent-hashing-pool = "akka.routing.ConsistentHashingPool"
115. consistent-hashing-group = "akka.routing.ConsistentHashingGroup"
116. }
118. deployment {
120. # deployment id pattern - on the format: /parent/child etc.
121. default {
123. # The id of the dispatcher to use for this actor.
124. # If undefined or empty the dispatcher specified in code
125. # (Props.withDispatcher) is used, or default-dispatcher if not
126. # specified at all.
127. dispatcher = ""
129. # The id of the mailbox to use for this actor.
130. # If undefined or empty the default mailbox of the configured dispatcher
131. # is used or if there is no mailbox configuration the mailbox specified
132. # in code (Props.withMailbox) is used.
133. # If there is a mailbox defined in the configured dispatcher then that
134. # overrides this setting.
135. mailbox = ""
137. # routing (load-balance) scheme to use
138. # - available: "from-code", "round-robin", "random", "smallest-mailbox",
139. # "scatter-gather", "broadcast"
140. # - or: Fully qualified class name of the router class.
141. # The class must extend akka.routing.CustomRouterConfig and
142. # have a public constructor with com.typesafe.config.Config
143. # and optional akka.actor.DynamicAccess parameter.
144. # - default is "from-code";
145. # Whether or not an actor is transformed to a Router is decided in code
146. # only (Props.withRouter). The type of router can be overridden in the
147. # configuration; specifying "from-code" means that the values specified
148. # in the code shall be used.
149. # In case of routing, the actors to be routed to can be specified
150. # in several ways:
151. # - nr-of-instances: will create that many children
152. # - routees.paths: will route messages to these paths using ActorSelection,
153. # i.e. will not create children
154. # - resizer: dynamically resizable number of routees as specified in
155. # resizer below
156. router = "from-code"
158. # number of children to create in case of a router;
159. # this setting is ignored if routees.paths is given
160. nr-of-instances = 1
162. # within is the timeout used for routers containing future calls
163. within = 5 seconds
165. # number of virtual nodes per node for consistent-hashing router
166. virtual-nodes-factor = 10
168. tail-chopping-router {
169. # interval is duration between sending message to next routee
170. interval = 10 milliseconds
171. }
173. routees {
174. # Alternatively to giving nr-of-instances you can specify the full
175. # paths of those actors which should be routed to. This setting takes
176. # precedence over nr-of-instances
177. paths = []
178. }
180. # To use a dedicated dispatcher for the routees of the pool you can
181. # define the dispatcher configuration inline with the property name
182. # 'pool-dispatcher' in the deployment section of the router.
183. # For example:
184. # pool-dispatcher {
185. # fork-join-executor.parallelism-min = 5
186. # fork-join-executor.parallelism-max = 5
187. # }
189. # Routers with dynamically resizable number of routees; this feature is
190. # enabled by including (parts of) this section in the deployment
191. resizer {
193. enabled = off
195. # The fewest number of routees the router should ever have.
196. lower-bound = 1
198. # The most number of routees the router should ever have.
199. # Must be greater than or equal to lower-bound.
200. upper-bound = 10
202. # Threshold used to evaluate if a routee is considered to be busy
203. # (under pressure). Implementation depends on this value (default is 1).
204. # 0: number of routees currently processing a message.
205. # 1: number of routees currently processing a message has
206. # some messages in mailbox.
207. # > 1: number of routees with at least the configured pressure-threshold
208. # messages in their mailbox. Note that estimating mailbox size of
209. # default UnboundedMailbox is O(N) operation.
210. pressure-threshold = 1
212. # Percentage to increase capacity whenever all routees are busy.
213. # For example, 0.2 would increase 20% (rounded up), i.e. if current
214. # capacity is 6 it will request an increase of 2 more routees.
215. rampup-rate = 0.2
217. # Minimum fraction of busy routees before backing off.
218. # For example, if this is 0.3, then we'll remove some routees only when
219. # less than 30% of routees are busy, i.e. if current capacity is 10 and
220. # 3 are busy then the capacity is unchanged, but if 2 or less are busy
221. # the capacity is decreased.
222. # Use 0.0 or negative to avoid removal of routees.
223. backoff-threshold = 0.3
225. # Fraction of routees to be removed when the resizer reaches the
226. # backoffThreshold.
227. # For example, 0.1 would decrease 10% (rounded up), i.e. if current
228. # capacity is 9 it will request an decrease of 1 routee.
229. backoff-rate = 0.1
231. # Number of messages between resize operation.
232. # Use 1 to resize before each message.
233. messages-per-resize = 10
234. }
235. }
236. }
238. default-dispatcher {
239. # Must be one of the following
240. # Dispatcher, PinnedDispatcher, or a FQCN to a class inheriting
241. # MessageDispatcherConfigurator with a public constructor with
242. # both com.typesafe.config.Config parameter and
243. # akka.dispatch.DispatcherPrerequisites parameters.
244. # PinnedDispatcher must be used together with executor=thread-pool-executor.
245. type = "Dispatcher"
247. # Which kind of ExecutorService to use for this dispatcher
248. # Valid options:
249. # - "default-executor" requires a "default-executor" section
250. # - "fork-join-executor" requires a "fork-join-executor" section
251. # - "thread-pool-executor" requires a "thread-pool-executor" section
252. # - A FQCN of a class extending ExecutorServiceConfigurator
253. executor = "default-executor"
255. # This will be used if you have set "executor = "default-executor"".
256. # If an ActorSystem is created with a given ExecutionContext, this
257. # ExecutionContext will be used as the default executor for all
258. # dispatchers in the ActorSystem configured with
259. # executor = "default-executor". Note that "default-executor"
260. # is the default value for executor, and therefore used if not
261. # specified otherwise. If no ExecutionContext is given,
262. # the executor configured in "fallback" will be used.
263. default-executor {
264. fallback = "fork-join-executor"
265. }
267. # This will be used if you have set "executor = "fork-join-executor""
268. fork-join-executor {
269. # Min number of threads to cap factor-based parallelism number to
270. parallelism-min = 8
272. # The parallelism factor is used to determine thread pool size using the
273. # following formula: ceil(available processors * factor). Resulting size
274. # is then bounded by the parallelism-min and parallelism-max values.
275. parallelism-factor = 3.0
277. # Max number of threads to cap factor-based parallelism number to
278. parallelism-max = 64
279. }
281. # This will be used if you have set "executor = "thread-pool-executor""
282. thread-pool-executor {
283. # Keep alive time for threads
284. keep-alive-time = 60s
286. # Min number of threads to cap factor-based core number to
287. core-pool-size-min = 8
289. # The core pool size factor is used to determine thread pool core size
290. # using the following formula: ceil(available processors * factor).
291. # Resulting size is then bounded by the core-pool-size-min and
292. # core-pool-size-max values.
293. core-pool-size-factor = 3.0
295. # Max number of threads to cap factor-based number to
296. core-pool-size-max = 64
298. # Minimum number of threads to cap factor-based max number to
299. # (if using a bounded task queue)
300. max-pool-size-min = 8
302. # Max no of threads (if using a bounded task queue) is determined by
303. # calculating: ceil(available processors * factor)
304. max-pool-size-factor = 3.0
306. # Max number of threads to cap factor-based max number to
307. # (if using a bounded task queue)
308. max-pool-size-max = 64
310. # Specifies the bounded capacity of the task queue (< 1 == unbounded)
311. task-queue-size = -1
313. # Specifies which type of task queue will be used, can be "array" or
314. # "linked" (default)
315. task-queue-type = "linked"
317. # Allow core threads to time out
318. allow-core-timeout = on
319. }
321. # How long time the dispatcher will wait for new actors until it shuts down
322. shutdown-timeout = 1s
324. # Throughput defines the number of messages that are processed in a batch
325. # before the thread is returned to the pool. Set to 1 for as fair as possible.
326. throughput = 5
328. # Throughput deadline for Dispatcher, set to 0 or negative for no deadline
329. throughput-deadline-time = 0ms
331. # For BalancingDispatcher: If the balancing dispatcher should attempt to
332. # schedule idle actors using the same dispatcher when a message comes in,
333. # and the dispatchers ExecutorService is not fully busy already.
334. attempt-teamwork = on
336. # If this dispatcher requires a specific type of mailbox, specify the
337. # fully-qualified class name here; the actually created mailbox will
338. # be a subtype of this type. The empty string signifies no requirement.
339. mailbox-requirement = ""
340. }
342. default-mailbox {
343. # FQCN of the MailboxType. The Class of the FQCN must have a public
344. # constructor with
345. # (akka.actor.ActorSystem.Settings, com.typesafe.config.Config) parameters.
346. mailbox-type = "akka.dispatch.UnboundedMailbox"
348. # If the mailbox is bounded then it uses this setting to determine its
349. # capacity. The provided value must be positive.
350. # NOTICE:
351. # Up to version 2.1 the mailbox type was determined based on this setting;
352. # this is no longer the case, the type must explicitly be a bounded mailbox.
353. mailbox-capacity = 1000
355. # If the mailbox is bounded then this is the timeout for enqueueing
356. # in case the mailbox is full. Negative values signify infinite
357. # timeout, which should be avoided as it bears the risk of dead-lock.
358. mailbox-push-timeout-time = 10s
360. # For Actor with Stash: The default capacity of the stash.
361. # If negative (or zero) then an unbounded stash is used (default)
362. # If positive then a bounded stash is used and the capacity is set using
363. # the property
364. stash-capacity = -1
365. }
367. mailbox {
368. # Mapping between message queue semantics and mailbox configurations.
369. # Used by akka.dispatch.RequiresMessageQueue[T] to enforce different
370. # mailbox types on actors.
371. # If your Actor implements RequiresMessageQueue[T], then when you create
372. # an instance of that actor its mailbox type will be decided by looking
373. # up a mailbox configuration via T in this mapping
374. requirements {
375. "akka.dispatch.UnboundedMessageQueueSemantics" =
376. akka.actor.mailbox.unbounded-queue-based
377. "akka.dispatch.BoundedMessageQueueSemantics" =
378. akka.actor.mailbox.bounded-queue-based
379. "akka.dispatch.DequeBasedMessageQueueSemantics" =
380. akka.actor.mailbox.unbounded-deque-based
381. "akka.dispatch.UnboundedDequeBasedMessageQueueSemantics" =
382. akka.actor.mailbox.unbounded-deque-based
383. "akka.dispatch.BoundedDequeBasedMessageQueueSemantics" =
384. akka.actor.mailbox.bounded-deque-based
385. "akka.dispatch.MultipleConsumerSemantics" =
386. akka.actor.mailbox.unbounded-queue-based
387. }
389. unbounded-queue-based {
390. # FQCN of the MailboxType, The Class of the FQCN must have a public
391. # constructor with (akka.actor.ActorSystem.Settings,
392. # com.typesafe.config.Config) parameters.
393. mailbox-type = "akka.dispatch.UnboundedMailbox"
394. }
396. bounded-queue-based {
397. # FQCN of the MailboxType, The Class of the FQCN must have a public
398. # constructor with (akka.actor.ActorSystem.Settings,
399. # com.typesafe.config.Config) parameters.
400. mailbox-type = "akka.dispatch.BoundedMailbox"
401. }
403. unbounded-deque-based {
404. # FQCN of the MailboxType, The Class of the FQCN must have a public
405. # constructor with (akka.actor.ActorSystem.Settings,
406. # com.typesafe.config.Config) parameters.
407. mailbox-type = "akka.dispatch.UnboundedDequeBasedMailbox"
408. }
410. bounded-deque-based {
411. # FQCN of the MailboxType, The Class of the FQCN must have a public
412. # constructor with (akka.actor.ActorSystem.Settings,
413. # com.typesafe.config.Config) parameters.
414. mailbox-type = "akka.dispatch.BoundedDequeBasedMailbox"
415. }
416. }
418. debug {
419. # enable function of Actor.loggable(), which is to log any received message
420. # at DEBUG level, see the “Testing Actor Systems” section of the Akka
421. # Documentation at http://akka.io/docs
422. receive = off
424. # enable DEBUG logging of all AutoReceiveMessages (Kill, PoisonPill et.c.)
425. autoreceive = off
427. # enable DEBUG logging of actor lifecycle changes
428. lifecycle = off
430. # enable DEBUG logging of all LoggingFSMs for events, transitions and timers
431. fsm = off
433. # enable DEBUG logging of subscription changes on the eventStream
434. event-stream = off
436. # enable DEBUG logging of unhandled messages
437. unhandled = off
439. # enable WARN logging of misconfigured routers
440. router-misconfiguration = off
441. }
443. # Entries for pluggable serializers and their bindings.
444. serializers {
445. java = "akka.serialization.JavaSerializer"
446. bytes = "akka.serialization.ByteArraySerializer"
447. }
449. # Class to Serializer binding. You only need to specify the name of an
450. # interface or abstract base class of the messages. In case of ambiguity it
451. # is using the most specific configured class, or giving a warning and
452. # choosing the “first” one.
453. #
454. # To disable one of the default serializers, assign its class to "none", like
455. # "java.io.Serializable" = none
456. serialization-bindings {
457. "[B" = bytes
458. "java.io.Serializable" = java
459. }
461. # Configuration items which are used by the akka.actor.ActorDSL._ methods
462. dsl {
463. # Maximum queue size of the actor created by newInbox(); this protects
464. # against faulty programs which use select() and consistently miss messages
465. inbox-size = 1000
467. # Default timeout to assume for operations like Inbox.receive et al
468. default-timeout = 5s
469. }
470. }
472. # Used to set the behavior of the scheduler.
473. # Changing the default values may change the system behavior drastically so make
474. # sure you know what you're doing! See the Scheduler section of the Akka
475. # Documentation for more details.
476. scheduler {
477. # The LightArrayRevolverScheduler is used as the default scheduler in the
478. # system. It does not execute the scheduled tasks on exact time, but on every
479. # tick, it will run everything that is (over)due. You can increase or decrease
480. # the accuracy of the execution timing by specifying smaller or larger tick
481. # duration. If you are scheduling a lot of tasks you should consider increasing
482. # the ticks per wheel.
483. # Note that it might take up to 1 tick to stop the Timer, so setting the
484. # tick-duration to a high value will make shutting down the actor system
485. # take longer.
486. tick-duration = 10ms
488. # The timer uses a circular wheel of buckets to store the timer tasks.
489. # This should be set such that the majority of scheduled timeouts (for high
490. # scheduling frequency) will be shorter than one rotation of the wheel
491. # (ticks-per-wheel * ticks-duration)
492. # THIS MUST BE A POWER OF TWO!
493. ticks-per-wheel = 512
495. # This setting selects the timer implementation which shall be loaded at
496. # system start-up.
497. # The class given here must implement the akka.actor.Scheduler interface
498. # and offer a public constructor which takes three arguments:
499. # 1) com.typesafe.config.Config
500. # 2) akka.event.LoggingAdapter
501. # 3) java.util.concurrent.ThreadFactory
502. implementation = akka.actor.LightArrayRevolverScheduler
504. # When shutting down the scheduler, there will typically be a thread which
505. # needs to be stopped, and this timeout determines how long to wait for
506. # that to happen. In case of timeout the shutdown of the actor system will
507. # proceed without running possibly still enqueued tasks.
508. shutdown-timeout = 5s
509. }
511. io {
513. # By default the select loops run on dedicated threads, hence using a
514. # PinnedDispatcher
515. pinned-dispatcher {
516. type = "PinnedDispatcher"
517. executor = "thread-pool-executor"
518. thread-pool-executor.allow-core-pool-timeout = off
519. }
521. tcp {
523. # The number of selectors to stripe the served channels over; each of
524. # these will use one select loop on the selector-dispatcher.
525. nr-of-selectors = 1
527. # Maximum number of open channels supported by this TCP module; there is
528. # no intrinsic general limit, this setting is meant to enable DoS
529. # protection by limiting the number of concurrently connected clients.
530. # Also note that this is a "soft" limit; in certain cases the implementation
531. # will accept a few connections more or a few less than the number configured
532. # here. Must be an integer > 0 or "unlimited".
533. max-channels = 256000
535. # When trying to assign a new connection to a selector and the chosen
536. # selector is at full capacity, retry selector choosing and assignment
537. # this many times before giving up
538. selector-association-retries = 10
540. # The maximum number of connection that are accepted in one go,
541. # higher numbers decrease latency, lower numbers increase fairness on
542. # the worker-dispatcher
543. batch-accept-limit = 10
545. # The number of bytes per direct buffer in the pool used to read or write
546. # network data from the kernel.
547. direct-buffer-size = 128 KiB
549. # The maximal number of direct buffers kept in the direct buffer pool for
550. # reuse.
551. direct-buffer-pool-limit = 1000
553. # The duration a connection actor waits for a `Register` message from
554. # its commander before aborting the connection.
555. register-timeout = 5s
557. # The maximum number of bytes delivered by a `Received` message. Before
558. # more data is read from the network the connection actor will try to
559. # do other work.
560. max-received-message-size = unlimited
562. # Enable fine grained logging of what goes on inside the implementation.
563. # Be aware that this may log more than once per message sent to the actors
564. # of the tcp implementation.
565. trace-logging = off
567. # Fully qualified config path which holds the dispatcher configuration
568. # to be used for running the select() calls in the selectors
569. selector-dispatcher = "akka.io.pinned-dispatcher"
571. # Fully qualified config path which holds the dispatcher configuration
572. # for the read/write worker actors
573. worker-dispatcher = "akka.actor.default-dispatcher"
575. # Fully qualified config path which holds the dispatcher configuration
576. # for the selector management actors
577. management-dispatcher = "akka.actor.default-dispatcher"
579. # Fully qualified config path which holds the dispatcher configuration
580. # on which file IO tasks are scheduled
581. file-io-dispatcher = "akka.actor.default-dispatcher"
583. # The maximum number of bytes (or "unlimited") to transfer in one batch
584. # when using `WriteFile` command which uses `FileChannel.transferTo` to
585. # pipe files to a TCP socket. On some OS like Linux `FileChannel.transferTo`
586. # may block for a long time when network IO is faster than file IO.
587. # Decreasing the value may improve fairness while increasing may improve
588. # throughput.
589. file-io-transferTo-limit = 512 KiB
591. # The number of times to retry the `finishConnect` call after being notified about
592. # OP_CONNECT. Retries are needed if the OP_CONNECT notification doesn't imply that
593. # `finishConnect` will succeed, which is the case on Android.
594. finish-connect-retries = 5
595. }
597. udp {
599. # The number of selectors to stripe the served channels over; each of
600. # these will use one select loop on the selector-dispatcher.
601. nr-of-selectors = 1
603. # Maximum number of open channels supported by this UDP module Generally
604. # UDP does not require a large number of channels, therefore it is
605. # recommended to keep this setting low.
606. max-channels = 4096
608. # The select loop can be used in two modes:
609. # - setting "infinite" will select without a timeout, hogging a thread
610. # - setting a positive timeout will do a bounded select call,
611. # enabling sharing of a single thread between multiple selectors
612. # (in this case you will have to use a different configuration for the
613. # selector-dispatcher, e.g. using "type=Dispatcher" with size 1)
614. # - setting it to zero means polling, i.e. calling selectNow()
615. select-timeout = infinite
617. # When trying to assign a new connection to a selector and the chosen
618. # selector is at full capacity, retry selector choosing and assignment
619. # this many times before giving up
620. selector-association-retries = 10
622. # The maximum number of datagrams that are read in one go,
623. # higher numbers decrease latency, lower numbers increase fairness on
624. # the worker-dispatcher
625. receive-throughput = 3
627. # The number of bytes per direct buffer in the pool used to read or write
628. # network data from the kernel.
629. direct-buffer-size = 128 KiB
631. # The maximal number of direct buffers kept in the direct buffer pool for
632. # reuse.
633. direct-buffer-pool-limit = 1000
635. # The maximum number of bytes delivered by a `Received` message. Before
636. # more data is read from the network the connection actor will try to
637. # do other work.
638. received-message-size-limit = unlimited
640. # Enable fine grained logging of what goes on inside the implementation.
641. # Be aware that this may log more than once per message sent to the actors
642. # of the tcp implementation.
643. trace-logging = off
645. # Fully qualified config path which holds the dispatcher configuration
646. # to be used for running the select() calls in the selectors
647. selector-dispatcher = "akka.io.pinned-dispatcher"
649. # Fully qualified config path which holds the dispatcher configuration
650. # for the read/write worker actors
651. worker-dispatcher = "akka.actor.default-dispatcher"
653. # Fully qualified config path which holds the dispatcher configuration
654. # for the selector management actors
655. management-dispatcher = "akka.actor.default-dispatcher"
656. }
658. udp-connected {
660. # The number of selectors to stripe the served channels over; each of
661. # these will use one select loop on the selector-dispatcher.
662. nr-of-selectors = 1
664. # Maximum number of open channels supported by this UDP module Generally
665. # UDP does not require a large number of channels, therefore it is
666. # recommended to keep this setting low.
667. max-channels = 4096
669. # The select loop can be used in two modes:
670. # - setting "infinite" will select without a timeout, hogging a thread
671. # - setting a positive timeout will do a bounded select call,
672. # enabling sharing of a single thread between multiple selectors
673. # (in this case you will have to use a different configuration for the
674. # selector-dispatcher, e.g. using "type=Dispatcher" with size 1)
675. # - setting it to zero means polling, i.e. calling selectNow()
676. select-timeout = infinite
678. # When trying to assign a new connection to a selector and the chosen
679. # selector is at full capacity, retry selector choosing and assignment
680. # this many times before giving up
681. selector-association-retries = 10
683. # The maximum number of datagrams that are read in one go,
684. # higher numbers decrease latency, lower numbers increase fairness on
685. # the worker-dispatcher
686. receive-throughput = 3
688. # The number of bytes per direct buffer in the pool used to read or write
689. # network data from the kernel.
690. direct-buffer-size = 128 KiB
692. # The maximal number of direct buffers kept in the direct buffer pool for
693. # reuse.
694. direct-buffer-pool-limit = 1000
696. # The maximum number of bytes delivered by a `Received` message. Before
697. # more data is read from the network the connection actor will try to
698. # do other work.
699. received-message-size-limit = unlimited
701. # Enable fine grained logging of what goes on inside the implementation.
702. # Be aware that this may log more than once per message sent to the actors
703. # of the tcp implementation.
704. trace-logging = off
706. # Fully qualified config path which holds the dispatcher configuration
707. # to be used for running the select() calls in the selectors
708. selector-dispatcher = "akka.io.pinned-dispatcher"
710. # Fully qualified config path which holds the dispatcher configuration
711. # for the read/write worker actors
712. worker-dispatcher = "akka.actor.default-dispatcher"
714. # Fully qualified config path which holds the dispatcher configuration
715. # for the selector management actors
716. management-dispatcher = "akka.actor.default-dispatcher"
717. }
719. }
722. }
akka-agent
1. ####################################
2. # Akka Agent Reference Config File #
3. ####################################
5. # This is the reference config file that contains all the default settings.
6. # Make your edits/overrides in your application.conf.
8. akka {
9. agent {
11. # The dispatcher used for agent-send-off actor
12. send-off-dispatcher {
13. executor = thread-pool-executor
14. type = PinnedDispatcher
15. }
17. # The dispatcher used for agent-alter-off actor
18. alter-off-dispatcher {
19. executor = thread-pool-executor
20. type = PinnedDispatcher
21. }
22. }
23. }
akka-camel
1. ####################################
2. # Akka Camel Reference Config File #
3. ####################################
5. # This is the reference config file that contains all the default settings.
6. # Make your edits/overrides in your application.conf.
8. akka {
9. camel {
10. # FQCN of the ContextProvider to be used to create or locate a CamelContext
11. # it must implement akka.camel.ContextProvider and have a no-arg constructor
12. # the built-in default create a fresh DefaultCamelContext
13. context-provider = akka.camel.DefaultContextProvider
15. # Whether JMX should be enabled or disabled for the Camel Context
16. jmx = off
17. # enable/disable streaming cache on the Camel Context
18. streamingCache = on
19. consumer {
20. # Configured setting which determines whether one-way communications
21. # between an endpoint and this consumer actor
22. # should be auto-acknowledged or application-acknowledged.
23. # This flag has only effect when exchange is in-only.
24. auto-ack = on
26. # When endpoint is out-capable (can produce responses) reply-timeout is the
27. # maximum time the endpoint can take to send the response before the message
28. # exchange fails. This setting is used for out-capable, in-only,
29. # manually acknowledged communication.
30. reply-timeout = 1m
32. # The duration of time to await activation of an endpoint.
33. activation-timeout = 10s
34. }
36. #Scheme to FQCN mappings for CamelMessage body conversions
37. conversions {
38. "file" = "java.io.InputStream"
39. }
40. }
41. }
akka-cluster
``` 1. ###################################### 2. # Akka Cluster Reference Config File # 3. ######################################
-
This is the reference config file that contains all the default settings.
-
Make your edits/overrides in your application.conf.
-
akka {
-
cluster {
-
Initial contact points of the cluster.
-
The nodes to join automatically at startup.
-
Comma separated full URIs defined by a string on the form of
-
"akka.tcp://system@hostname:port"
-
Leave as empty if the node is supposed to be joined manually.
-
seed-nodes = []
-
how long to wait for one of the seed nodes to reply to initial join request
-
seed-node-timeout = 5s
-
If a join request fails it will be retried after this period.
-
Disable join retry by specifying "off".
-
retry-unsuccessful-join-after = 10s
-
Should the 'leader' in the cluster be allowed to automatically mark
-
unreachable nodes as DOWN after a configured time of unreachability?
-
Using auto-down implies that two separate clusters will automatically be
-
formed in case of network partition.
-
Disable with "off" or specify a duration to enable auto-down.
-
auto-down-unreachable-after = off
-
deprecated in 2.3, use 'auto-down-unreachable-after' instead
-
auto-down = off
-
The roles of this member. List of strings, e.g. roles = ["A", "B"].
-
The roles are part of the membership information and can be used by
-
routers or other services to distribute work to certain member types,
-
e.g. front-end and back-end nodes.
-
roles = []
-
role {
-
Minimum required number of members of a certain role before the leader
-
changes member status of 'Joining' members to 'Up'. Typically used together
-
with 'Cluster.registerOnMemberUp' to defer some action, such as starting
-
actors, until the cluster has reached a certain size.
-
E.g. to require 2 nodes with role 'frontend' and 3 nodes with role 'backend':
-
frontend.min-nr-of-members = 2
-
backend.min-nr-of-members = 3
-
<role-name>.mi
(本文超出站点单文档体积上限,已截断)
