I have a server running expressjs that hosts the admin website and 4 to 10 additional worker servers that run a job scheduler and are constantly processing jobs and receiving new data. Is there a good way for the worker servers to notify the website server and then update the data on the website using websockets?
Worker servers can use any number of means for communicating with your main server. For example, you main server could have a special web server in your main server (not exposed to the outside world) that just receives http requests with data from the workers. So, whenever a worker gets new data, it just sends an http request to the main server.
Or, either webSocket or socket.io can be used server-to-server just fine (one end serves as the client for establishing the connection) and the other is the webSocket/socket.io server listening for incoming connections. In your case, the workers would be the clients and they would connection to your main server and then they can send data whenever they want over the webSocket or socket.io connection.
If you then want to automatically update data in various web browsers that have one of your pages open, those pages would also have a webSocket or socket.io connection open to your server so when your server gets new data, it could then tell the web page about it and the webpage could update its display without constantly refreshing/reloading a new page.
Either ws or socket.io can be used. Socket.io offers a number of features built on top of webSocket. You would choose socket.io if you want those added features. You can see a partial list of the added socket.io features here:
Moving from socket.io to raw websockets?
Related
I'm building an app that will call a web service that has 2 identical instances, each running on a different server, with its own IP.
The app can call any service instance at any time, but sometimes it may have difficulties getting a response from one of them (because of a network failure or a problem with the instance).
What is the recommended way to make the app automatically stop using the problematic instance?
How can it get back to using the instance when it's online again?
Are there standard libraries or tools to help this kind of scenario?
Use a load balancer.
You app will have to connect to the LB and not to the web servers directly. LBs maintain status of each server they are configured with ( through timeout or explicit http status calls). They automatically disable traffic from the disconnected servers and enable it once the instance is back.
Later on you can add or remove instances based upon your requirements ( manual or auto-scaling ) without requiring any changes in your app.
HAProxy and Nginx are widely used for internet scale load balancing. Cloud providers also provides this as a service, you can use them if you are on cloud ( like AWS has elastic load balancing, Google Cloud has Load Balancing ).
I am writing a client for an HTTP API which is not yet publicly available.
Based on the specs I got, I have mocked a server which simulates the API, to test how my client reacts.
This server is a very simple Rack application, which currently runs on WEBRick.
The API client interacts with this fake API et performs correctly in the different tests cases.
Hopefully, I will just have to change the hostname in the config file when the API goes live.
However, I know for a fact that the API will be put under heavy load when it goes live. My client will thus most likely have to face :
HTTP timeouts
Jitter
Dropped TCP connections
503 Responses
...
I know that my client performs well in an ideal scenario, but how can I randomly (or not randomly) introduce these behaviors in my test cases, to verify that the client handles these errors correctly ?
Is there some kind of reverse proxy that can be configured to simulate these errors when serving data from a stable server on a stable network (in my case : local server on localhost) ?
You can try Net Limiter (http://www.netlimiter.com/) to shape bandwidth.
On the other hand, to make more accurate simulations you need to control both server and client side.
For instance, to simulate timeout condition your mock server can receive request from HTTP API client and then stop, hence triggering timeout on client side.
Other benefits of your own mock/test server is that you can emulate dropped TCP connections (just close newly received client connection), 50X responses, invalid responses, protocol breaking responses and much more.
I have a chat application developed using WCF call back contract.This use netTcp binding for the client server communication.
Client is a Windows Forms application will be running in the client machine(XP or Windows8 machine)
This WCF service hosted as a windows service in the server machine.I am maintaining a Client Session list in the service, this will store the details about each client connected to the server, this list is static variable.
The work flow is, whenever a client connect to the server using the connect operation,client details will be added to the client session list,this session list will be used by the server to send message back to the client whenever its needed.
Everything works fine in the single server environment,Now I want to know how can I handle this in the load balancing scenario, that means I have two server machine,at a time one server will be active.if Server 1 is fail, Server 2 will be active. In this scenario, How can I manage my client sessions share between two servers and working as usual with out disturbing my clients?
One option is to use a Session State store provider, which will provide the session state for both instances of server service.
As MSDN states: http://msdn.microsoft.com/en-us/library/z414bbk9(v=vs.100).aspx
for Web farm configurations, it can be stored out of process using
either the ASP.NET State service or a Microsoft SQL Server database.
The ASP.NET state service is quite well documented http://msdn.microsoft.com/en-us/library/ms178581(v=vs.100).aspx
As for the database solution... well... you have to analyse the added overhead due to database access.
Also, if you are hosting the service using IIS, you could consider using Out-of-Process session state (http://technet.microsoft.com/en-us/library/cc754032%28v=ws.10%29.aspx).
These are just some ideas. You can look into other web farm synchronization techniques made available for Microsoft technologies.
I would like to know about load balancing servers.
I am having an application which is having load balanced server.
When i made some changes to the data, in my application how it is taking effect?
Also, when we restart the application , what are all the steps that are happening, to a load balanced server?
well, the load balancer is separate from the application code, basically it is just routing the requests to one of a number of set up servers (a.k.a. downstream servers, for instance web application servers, apache/nginx+php, etc) that handles the actual request. So to update the application (i.e. java servlet, JSP, PHP page, static HTML page, image, etc) all the downstream servers will have to be updated. As for data (i.e. articles, user database, etc) this will usually be stored in a database that all the downstream servers connect to
As for restarting the application, when you do that on each of the downstream servers it will temporarily be unable to service requests, the load balancer will thus get an "unable to connect" issue when trying to send requests to the server with the application being restarted, and will then try to send the request to the next server in the list of downstream servers. Depending on how the load balancer is set up it will automatically retry sending new requests to the previously restarted server and when the restarted downstream server is up again it will again service requests. So to update the applications you basically just update one downstream server at the time, as the other servers take over the load while it is restarted it will be no downtime, and the clients will be none the wiser
Is this a hardware appliance or at server running HAProxy/nginx/other?
If two web servers are configured in between a load balancer and a weblogic cluster, will the two Apache server maintain session stickiness?
Say for example, the load balancer forwards the first request to the 1st apache and in turn 1st apache forwards to 1st WL managed instance. Even if the second req from the same user is forwarded by the load balancer to the second apache, will the second apache be able to forward it to the 1st WLManaged instance which served the first request rather than the second WLManaged instance which is not aware of the session information at all.
What should ideally be the behaviour of the weblogic apache plugin? The catch is I don't want to enable session replication on the wl server cluster.
According to the section "Failover, Cookies, and HTTP Sessions" of the Apache HTTP Server Plug-In:
When a request contains session information stored in a cookie or in the POST data, or encoded in a URL, the session ID contains a reference to the specific server instance in which the session was originally established (called the primary server) and a reference to an additional server where the original session is replicated (called the secondary server). A request containing a cookie attempts to connect to the primary server. If that attempt fails, the request is routed to the secondary server. If both the primary and secondary servers fail, the session is lost and the plug-in attempts to make a fresh connection to another server in the dynamic cluster list. See Figure 3-1 Connection Failover.
Note: If the POST data is larger than 64K, the plug-in will not parse the POST data to obtain the session ID. Therefore, if you store the session ID in the POST data, the plug-in cannot route the request to the correct primary or secondary server, resulting in possible loss of session data.
Figure 3-1 Connection Failover
In other words, yes, both Apache servers will be able to forward an incoming request to the "right" WebLogic instance as the session ID contains all the required information for that. Note that there is no real need to confirm this with testing but it would very easy though.
UPDATE: Answering the following comment from the OP
I think this document stands good for only one apache server. In my case I have two and the load balancer forwards the requests to both the servers in a 50:50 manner. I did test this and the weblogic plugin is not maintaining the stickiness.
I understood you are using two apache fontend and I'm not sure this document applies to configuration with one apache server only. As explained, the session ID contains a reference of the primary server (and the secondary server as well) so both apache should be able to deal with it. At least, this is my understanding. Actually, I've worked with a similar configuration in the past but can't remember if things were working as I think they should or if the load balancer was configured to handle stickiness too (i.e. forward to a given Apache server). I have a little doubt now...
Could post your plugin configuration (of both apache server if they differ)? Could you also confirm that things are working as expected when only one apache server is up (and test this with both apache if their configuration differ, which shouldn't be the case though)?
When you have 2 Apache instances with a TCP load balancer in front, the stateflow diagram is not applicable anymore, because the Apache instances do not share their states.
I guess that the WebLogic plug-in maintains a state with a directional mapping [IPAddress+Port -> JVMID]. If it receives a cookie with a JVMID it does not know yet (for instance, it has never sent a request to this server yet), it has no way to know which IPAdress+Port it refers to, so it will not be able to reuse these JVMID and it will reassign new primary/secondary ones, which will be identical for 2 instances (maybe swapped), and which might be different if there are strictly more than 2 instances.
I did not confirm it by running specific tests, but on paper it seems not to work in all cases.
The answer is yes. We've got a write up of this on our blog http://blog.c2b2.co.uk/2012/10/basic-clustering-with-weblogic-12c-and.html which provides step by step instructions on setting up web session failover in a cluster.
Essentially the jsessionid cookie encodes the primary and secondary weblogic servers. Mod-wl parses the cookie and routes the request to the primary server. In your case Managed Server 1. If it is down it will automatically route the request to the backup server Managed Server 2.
The diagram above holds true for 2 Apache servers connected to the same WL cluster. The cookie session info contains details on what WLS to connect to and the plugin will respect that. If the primary (the server it originally connected to) WL server ins't available, then the request would be sent to the secondary server (designated such at the time of the first request based on the rules defined in selecting a "Preferred Replication Group"). This secondary server maintains the same session state as the primary WLS server and should be able to handle the request.
If session replication isn't setup (I think this is OFF by default), then there would be no session copied to another server and if the original/primary WL server goes down, you lose the session.
The answer is NO. As you have 2 Apache webserver, you need to implement stickiness at both hardware and software loadbalancer level in order to achieve your requirement.
Means you already have sticky session implemented in Weblogic plug-in for Apache level, but you also need Source IP based stickiness at the hardware loadbalancer level. This will allow your hardware loadbalancer to send the subsequent request from same user to same apace web server.