Are events always run in the same process in Nitrogen?
I'm taking about event
function in Nitrogen, the 开发者_运维知识库Erlang web framework, in a web module that is run when you get a postback.
Does event
always run in the same process for the same web client (that is, browser window or frame).
I've recall at least one case in which that didn't happen, but I can't reproduce it.
No, Nitrogen events get run in whichever process is currently handling the web request for nitrogen.
Since Nitrogen is a very asynchronous framework, you may have multiple processes handling multiple events for the same browser window or frame asynchronously. This means that you could very well have different events get handled by seperate processes.
Hey guys, i have discovered the process registry for nitrogen called: nprocreg.
When you check your apps folder ( $NITROGEN_INSTALL_DIR/apps/nprocreg ).
In this application, processes can be spawn across more than one nitrogen app servers even across multiple machines. To experiment with this, start 2 erlang nodes on two differnt hosts. ping them so that they are connected. (net_adm:ping(?OTHER_NODE)
). Now, start nitrogen on both erlang nodes. You could actually first start the nitrogen and then ping the two nodes
Make sure that the two nitrogen nodes are using long names i.e [NAME]@IP_ADDRESS on a LAN.
Now, on a third machine on your LAN, create a DNS (Name Server) . Put the same name mapping onto two different IP Adresses of our two nodes running the nitrogen applications. Configure the two computers runnind nitrogen to ensure that they point to the DNS IP address for DNS Services (Actually do this for all the computers in your LAN).
You will discover that when you request for a page (residing in the doc root of both nitrogen apps) from several computers on your LAN, using the mapped name in your browser you see that the DNS server does some kind of Load balancing.
Now, Ensure that the page you are requesting for can show you from which nitrogen server its coming from on the interface. This page must have say a button which generates an event that will wf:flash(wf:f("Some statement on the interface",[]))
Now, request this page on two different computers and note where each is being served from. Next, go to one nitrogen server and stop it.
When you now click on the button on the browser which got its page the nitrogen server that we have just put down, it still works.
This is why, Rusty and the friends discovered that if nitrogen processes can be registered across more nitrogen apps, when run behind a load balancer, the events can be fowarded to any nitrogen app in the cluster.
Of course this works well if you ensure that the two apps on different machines have the same pages, modules and configuration of paths. This is because the event call back function maybe calling say a database API.
An example of load balancing using DNS Server can be seen when you 'dig' google from your terminal on linux or solaris like this:
dig www.google.comYou will see that the name server has the same name mapped onto several Ip adresses. This ensures availability across domains and ensures some kind of load balancing
/joshmuza@gmail.com
精彩评论