Reputation: 4620
I have read through the Erlang documentation, in particular the topics regarding Erlang Ports and Erlang Nodes.
The tutorial uses the same example to present these two concepts, that of a program serving two simple functions, but despite some communication protocol differences, it does not clarify the advantages and disadvantages of using either concept.
At first sight, it seems that ports are much easier to setup servers in external languages, but I would like to know what Erlang Nodes can offer that Erlang Ports don't, and vice-versa.
Can anyone clarify on the functional and non-functional aspects of Erlang Ports vs Nodes?
Thank you
CLARIFICATION UPDATE
What I really want to compare is Erlang Ports vs Node written in non-ErlangVM languages (I know that Erlang Nodes are full Erlang VMs and hence much powerful than Ports). For example, what can a C Port do that a C Node cannot, and vice-versa?
Upvotes: 2
Views: 404
Reputation: 5646
There is nothing that CNode or Port can or cannot do. I think you missed to understand why each option was built, then it may help you decide which to pick.
CNode was built to help with distributing tasks across the cluster. Cluster is why you want this option.
Port was built to replace NIFs in case when there is existing linux device, command line tool or script available to accomplish task for you. You still can build erlang cluster since you erlang application will call port after all :) so you are not limited with this option.
Now imagine you have huge C/C++ e.g. postgres database, and you want to make it part of your cluster (dumb example but bear with me). You can fork source code, add CNODE code to it and transform RPC messages into queries, and event more, you can use postgres internal API which you wouldn't be able to have with just SQL queries. So port wouldn't be that helpful in this case since it is some external service running but ...you could build some extension in pstgresql, then expose it to SQL as some function and finally make standard SQL query in order to execute such function from erlang node.
As I said, each has it own place, it really depends what is your case and what existing solutions you have available and need to incorporate into your solution.
Upvotes: 7