java elasticsearch NodeBuilder 与 TranportClient
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15398861/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
elasticsearch NodeBuilder vs TranportClient
提问by im8bit
Probably a very easy (and dumb) question to other elasticsearch devs, what's the difference between these two?
对于其他弹性搜索开发人员来说,这可能是一个非常简单(且愚蠢)的问题,这两者之间有什么区别?
I'm connecting to a remote elasticsearch server from a Java webapp, so far I have been using TransportClient but I was wondering if NodeBuilder can be used to, or NodeBuilder should be used just for embedded clients?
我正在从 Java webapp 连接到远程 elasticsearch 服务器,到目前为止我一直在使用 TransportClient 但我想知道 NodeBuilder 是否可以用于,或者 NodeBuilder 应该只用于嵌入式客户端?
If any of the two can be used to connect to remote ES servers, which one should be better in terms of memory and performance?
如果两者中的任何一个都可以用于连接远程ES服务器,那么在内存和性能方面哪个应该更好?
If anyone can point me out to a NodeBuilder connecting to a remote ES server example would be great because I haven't had any lucky finding one.
如果有人能指出我连接到远程 ES 服务器示例的 NodeBuilder 会很棒,因为我没有幸运地找到一个。
Thanks.
谢谢。
回答by dadoonet
NodeBuilder can also be used to connect to a cluster.
NodeBuilder 也可用于连接到集群。
Node node = nodeBuilder().clusterName("yourcluster").client(true).node();
Client client = node.client();
It will join the cluster as another node and will be aware of the whole topology. Using nodes, you can use multicast to discover other running nodes.
它将作为另一个节点加入集群并了解整个拓扑。使用节点,您可以使用多播来发现其他正在运行的节点。
My opinion is that I prefer to use TransportClient
than NodeClient
because other cluster nodes won't receive useless information when the TransportClient stops. When a NodeClient stops, each node has to know that even if they don't have to manage it as it does not hold any data.
Also, I have seen in debug mode that NodeClient starts more Threads
than TransportCLient. So I think TransportClient has a lesser memory footprint.
我的观点是我更喜欢使用而TransportClient
不是NodeClient
因为当 TransportClient 停止时其他集群节点不会收到无用的信息。当 NodeClient 停止时,每个节点都必须知道,即使它们不必管理它,因为它不保存任何数据。此外,我在调试模式下看到 NodeClient 启动次数Threads
多于 TransportCLient。所以我认为 TransportClient 的内存占用较少。
By the way, if you are using Spring, you can use the spring-elasticsearchfactories for that. If not, you can always have a look at source code to see how I manage NodeClient vs TransportClient.
顺便说一句,如果您使用的是 Spring,您可以使用spring-elasticsearch工厂。如果没有,您可以随时查看源代码,了解我如何管理 NodeClient 与 TransportClient。
Hope this helps.
希望这可以帮助。
EDIT 2016-03-09: NodeClient
should not be used. If there is a need for that, people should create a client node (launch an elasticsearch node with node.data: false
and node.master: false
) and use a TransportClient
to connect to it locally.
编辑 2016-03-09:NodeClient
不应使用。如果需要,人们应该创建一个客户端节点(使用node.data: false
和启动一个弹性搜索节点node.master: false
)并使用 aTransportClient
在本地连接到它。
回答by Brimstedt
If I understood the documentation correctly, it's beneficial to use Node Client, at least if you have shards:
如果我正确理解了文档,那么使用 Node Client 是有益的,至少如果您有分片:
The benefit of using the [Node] Client is the fact that operations are automatically routed to the node(s) the operations need to be executed on, without performing a “double hop”. For example, the index operation will automatically be executed on the shard that it will end up existing at.
使用 [Node] Client 的好处是操作会自动路由到需要执行操作的节点,而无需执行“双跳”。例如,索引操作将自动在它最终存在的分片上执行。
vs
对比
It [Transport client] does not join the cluster, but simply gets one or more initial transport addresses and communicates with them in round robin fashion on each action (though most actions will probably be “two hop” operations).
它 [传输客户端] 不加入集群,而只是获取一个或多个初始传输地址,并在每个操作上以循环方式与它们通信(尽管大多数操作可能是“两跳”操作)。
As I interpret this, using a node (preferably with client set to true) that joins the cluster and then use the Client on that node, you will send requests directly to the correct node in the cluster.
正如我所解释的那样,使用加入集群的节点(最好将客户端设置为 true),然后在该节点上使用客户端,您将直接向集群中的正确节点发送请求。
Using TransportClient, you'll connect to any node, which will then redirect (or possibly forward the request, not sure) the request to the correct node ("two hops")
使用 TransportClient,您将连接到任何节点,然后该节点会将请求重定向(或可能转发请求,不确定)到正确的节点(“两跳”)
Using Node Client should be more efficient in terms of network traffic and load on nodes.
在网络流量和节点负载方面,使用 Node Client 应该更有效。
回答by user432024
Also people should know that Node client joins the full mesh cluster and also becomes a proxy so other clients can connect to it as well and also be able to server plugin sites, something to consider when locking down your cluster.
此外,人们应该知道 Node 客户端加入全网状集群并成为代理,因此其他客户端也可以连接到它,并且还可以服务器插件站点,这是在锁定集群时需要考虑的事情。
Node client can be used to do scatter gather so it can alleviate some processing from the data nodes.
节点客户端可用于进行分散收集,因此它可以减轻数据节点的一些处理。
Not sure if Transport client does scatter gather also.
不确定传输客户端是否也进行分散收集。