Reduce server load on live pm chat… |
Reduce server load on live pm chat… |
masonh928 |
Jan 13 2016, 02:57 PM
Post
#1
|
Serious Coder Group: Members Posts: 253 Joined: 17-August 13 From: Indiana Member No.: 19,570 |
Ok so basically I have a chat, and it retrieves messages from the database ever 500 miliseconds, now obviously this will run my CPU and hits like nothin. Therefore I would like a method to check whether or not messages have been received in the past 30 secs.
My objective is: Ok if a message is not sent within say, 30 secs, then the JS only retrieves message every, 20 secs or so; however, if there is back and forth messages, then retrieve every 500 or 1000 milliseconds. Can anyone give me the logic, I don't need the code… Very much appreciated, because my server is frozen for a few hours, therefore i need a solution lol! I have considered sockets, but I don't know how to implement them. |
masonh928 |
Jan 13 2016, 05:49 PM
Post
#2
|
Serious Coder Group: Members Posts: 253 Joined: 17-August 13 From: Indiana Member No.: 19,570 |
Should this be server-side?
|
Christian J |
Jan 13 2016, 06:27 PM
Post
#3
|
. Group: WDG Moderators Posts: 9,656 Joined: 10-August 06 Member No.: 7 |
Disclaimer: I'm not familiar with this.
Perhaps the browser's javascript/Ajax could check the timestamp of the DB's last entry: if it's recent, check again soon; if it's long ago, wait a little before checking again. |
CharlesEF |
Jan 13 2016, 06:38 PM
Post
#4
|
Programming Fanatic Group: Members Posts: 1,981 Joined: 27-April 13 From: Edinburg, Texas Member No.: 19,088 |
|
masonh928 |
Jan 13 2016, 07:59 PM
Post
#5
|
Serious Coder Group: Members Posts: 253 Joined: 17-August 13 From: Indiana Member No.: 19,570 |
I posted a question on SO, if any of you are interested on seeing any solutions.
http://stackoverflow.com/questions/3477991...-dbs-last-entry thanks Charles for the links, I will definitely check it out. |
masonh928 |
Jan 14 2016, 09:19 AM
Post
#6
|
Serious Coder Group: Members Posts: 253 Joined: 17-August 13 From: Indiana Member No.: 19,570 |
This tutorial part 5 of it has a counter to increment a timeout variable, I'm not following it for my code, but would like to implement the logic, can someone please help explain this part. Though this is more of a client side issue. I'm dumb sorry.
|
masonh928 |
Jan 15 2016, 06:33 PM
Post
#7
|
Serious Coder Group: Members Posts: 253 Joined: 17-August 13 From: Indiana Member No.: 19,570 |
They use a customized wrapper for requests…
|
Lo-Fi Version | Time is now: 25th April 2024 - 11:36 PM |