How to Avoid Temporary Website's server sleeping - server

I have a webApplication (Asp.net C#) and i need to send some data to another WebService at about 8:00am by my webApplication.
I used Timer class(static variable), timer's Elapsed(EventHandler) and interval(about 20min) to check hour and send data at 8:00am to WebService.
Every thing is good, and Timer's event handler run good.
but, after 2 hour if my website didnt have any request and Traffic, website will be sleep temporary! so timer and other static variable will be lost !! and task failed temporary!
Then, if one user send request to Visit the website, WebApplication will start again and timer and other Static variables will active!
if we haven't any visit or request, can we Avoid this Temporary Website's server sleeping?

Related

How facebook initializes recent news feed entries instantly?

I am developing a news feed module for my web project. News feed activities (post, filter, etc.) are nearly similar to Facebook. I ve used pagination pattern that initializes news page by page (eg: 20 post for every scroll) when user scrolls the page down (unlimited scrolling).
I wonder how Facebook initializes current news when one of your friends shares a post.
I guess it uses a trigger that sends an ajax request to get if new posts are exist. Using a timer trigger (with javascript timeout function which sends ajax requests every 10 seconds) would not be an effective solution for this problem.
Does anyone have any other trigger advices for me ?
Thanks in Advance.
If you were to monitor the network activity of the home page, you'd see calls to https://pct.channel.facebook.com/pull with some unique parameters attached to it. While watching it you'd see that the calls take a variable length of time, from 1 second to ~60 seconds.
This is referred to as Long-Polling, where the server waits until new information is available to send back a response. Meantime, the HTTP call is held in suspense as though the endpoint is loading. Once the server finds information available, it sends a response with the data, and closes the connection. Then the client re-opens the connection with another HTTP call once it receives data.

Cancel gwt rpc call

In this example there is a pretty description of how to make a timeout logic using a Timer#schedule. But there is a pitfall there. We have 2 rpc requests: first makes a lot of computation on server(or maybe retrieving a large amount of data from database) and second a tiny request that returns results immediately. If we make first request, we will not recieve results immediately, instead we will have a timeout and after timeout we make the second tiny request and then abortFlag from example will be true, so we can retrieve the results of second request, but also we can retrieve the results of first request that was timed out before(because the AsyncCallback object of first call was not destroyed).
So we need some kind of cancelling the first rpc call after timeout occurs. how can I do this?
Let me give you an analogy.
You, the boss, made a call to a supplier, to get some product info. Supplier say they need to call you back because the info would take some time to be gathered. So, you gave them the contact of your foreman.
Your foreman waits for the call. Then you told your foreman to cancel the info request if it takes more than 30 minutes.
Your foreman thinks you are bonkers because he cannot cancel the request, because he does not have an account that gives him privilege to access the supplier's ordering system.
So, your foreman simply ignores any response from the supplier after 30 minutes. Your ingenious foreman sets up a timer in his phone that ignores the call from the supplier after 30 minutes. Even if you killed your foreman, cut off all communication links, the vendor would still be busy servicing your request.
There is nothing on the GWT client-side to cancel. The callback is merely a javascript object waiting to be invoked.
To cancel the call, you need to tell the server-side to stop wasting cpu resources (if that is your concern). Your server-side must be programmed to provide a service API which when invoked would cancel the job and return immediately to trigger your GWT callback.
You can refresh the page, and that would discard the page request and close the socket, but the server side would still be running. And when the server side completes its tasks and tries to perform a http response, it would fail, saying in the server logs that it had lost the client socket.
It is a very straight forward piece of reasoning.
Therefore, it falls into the design of your servlet/service, how a previous request can be identified by a subsequent request.
Cascaded Callbacks
If request 2 is dependent on the status of request 1, you should perform a cascaded callback. If request 2 is to be run on success then, you should place request 2 into the onFailure block of the callback. Rather than submitting the two requests one after another.
Otherwise, your timer should trigger request 2, and request 2 would have two responsibilities:
tell the server to cancel the previous request
get the small piece of info

How to Resume the Persisted Workflow with Delay Activity without Reloading into memory

How to Resume the Persisted Workflow with Delay Activity without Reloading into memory:
I am creating a workflow for leave application. My requirement is if any participant is not responded in the specified time, then the request needs to pass to next level participant approval.
Suppose a requester submitted a Leave Request and the Team Lead needs to approve it within 7 days. If the Team Lead is not responded in 7 days, then automatically it has to go to Manager Approval.
In general to achieve this, we will write a Windows service which is checking periodically and send the notifications once the period is elapsed.
But I want to achieve without writing the Windows service. Is there any possibility in WF4.0.
I am trying like this, once the requester is submitted the request then I am showing the request in the participant mail box and persisting the workflow. Once the participant responded I am resuming the workflow (because I am saving the workflow instance ID) and passing the participant response for further workflow execution.
In this if the participant is not responded, how to escalate / send the request to manager without using windows service.
Is it possible to do with anything with the Delay Activity?
If you create a workflow service it is hosted in the WoskflowServiceHost and this periodically checks is there are expired timers and resumes those.
You must host the workflow engine somewhere ...
If it's not in a windows service, it should be in IIS.
You can also host it in a "normal" command line application, but if you close the application the workflow will stop.

How to emulate queue for CGI script?

In my CGI script i make long (up to 10 seconds) request to another server, parsing results and show response to my user (via AJAX). But another server owner ask me to perform each request no more than 1 request per 10 seconds so:
i need to save each request of my
user;
every ten seconds i can make only one
request to another server;
First i think about Cron which will open simple text file (queue file), read first line and send it as a request to another server. After that it will save result in another file (where i'll cache all results). So my CGI will first check cache file and try to find result in it and after that (if result is not found) it will save task in the queue file (for the Cron).
But Cron run only once per minute so my user must wait for so long time...
So how i can do this via CGI?
May be:
After checking the cache file CGI will
estimate time to complete request
(by reading current queue file) and
send this estimation time to the
HTML (where i can got this time and
make another request after this time
via AJAX).
After that it will save request to
the queue file and fork. The forked
process will wait untill it's
request will be on the top of the
queue and will make request to
another server.
After that it will save result in
the cache file. What you think?
May be some module already written for such tasks?
One option is to create a local daemon/service (Linux/Windows) that handles sending all requests to the remote server. Your web service can talk to this daemon instead of the remote service using the same protocol, except on a private port/socket. The daemon can accept requests from the web server/application and every ten seconds, if there is a pending request it can send it on to the remote server, and when there is a response, it can forward it back to the incoming request socket. You can think of this daemon as a proxy server that simply adds a queueing functionality. Note that the daemon doesn't actually have to parse either the incoming request or returning results; it just forwards the bits on to the destination in each case. It only has to implement the queueing and networking functionality.

Facebook notification system: Is it polling?

Notification when the user first login, not so hard, just require a database scan, I can deal with that. However, when a friend send a request or comment on profile X, a notification is sent, and almost immediately receive on the other end even when the user X not making any request. Is it polling? Does not feel like it, since the page never refresh itself. It must be something else? Anyone have any idea? maybe Web Push?
Facebook uses long-polling.
While you're on their page, they have a script continually issue requests to a particular URL. Instead of immediately responding, the server handling that URL first waits for a message to come in to its queue, and then sends that message out to the user. If a certain timeout is reached, the server responds without sending a message, and the client-side script makes another request to that URL.
To see this in action, open up Firebug's Net tab while on a Facebook page and wait for a couple minutes. You should see requests that last for a minute and then are followed up with a new request.
I believe they use AJAX/Javascript for that. It would allow the page to get information from the server and display it without reloading the page. You should be able to do this with an AJAX library like JQuery or something similar. As for whether or not Facebook itself does push or poll, I have no idea, but you can get a similar behavior by polling with AJAX.