Server sent events, server memory loading?


I want to use SSE(Server sent events) to send real time notifications to my app users.
I still in the planning phase in which I'm choosing between SSE/Web socket protocol.

From what I read, I see that the Ideal for my case is to SSE (Please advice if more).

About how SEE works, this is the workflow conclusion of what I understood :
"Client (browser) sends a request to the server via HTTP. It creates a process, which fetches latest state in the DB and responds back. Client gets server response and in N seconds sends next request to the server."

The problem I'm thinking about is that the server will start a loop which checks for something that need to be  notified , doesn't this mean that the server will not stop execution of the file containing this loop until he closes his browser ? Suppose my web app needs to be opened 8 hours per days, so for each user of the system, the file will still be executed for these 8 hours. and consume computer resources.

Is not his a heavy load on the server ?  or there is some play-around fro this point?

Appreciating any help,
Ramy MohsenAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

David Johnson, CD, MVPOwnerCommented:
The browser sends a request, you service the request, and send data back to the client.  This will be done once unless the browser has a timer that will resend the request.  The # of simultaneous requests is what will determine the server load
Ramy MohsenAuthor Commented:
Sorry didn't get it,
How the server will send it once?

I want the server to send real-time notifications to the client, not just send it once.

And that is what I understood about SSE, The the server side code will be like that:

while (true){
//check if new change need to be notified
//send response

Ramy MohsenAuthor Commented:
Any help?
David Johnson, CD, MVPOwnerCommented:
it is not a heavy load. less than a web server where a user refreshes the page. The cliient asks 'got any thing for me?' .. server replies 'no' client then closes the connection and sleeps the appropriate time and then the cycle begins again. Upon further thinking this is more of a client side event which if clients connect and disconnect at will.

othersise the server will check to see who is connected and then check for data to send and then queue it..then open a connection to the client who is continually listening. and send the data, the client will put the data in its incoming queue and then process/display it. until the queue is empty.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.