php ajax chat room will increase server load?

Ye' old general discussion board. Basically, for everything that isn't covered elsewhere. Come here to shoot the breeze, shoot your mouth off, or whatever suits your fancy.
This forum is not for asking programming related questions.

Moderator: General Moderators

User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: php ajax chat room will increase server load?

Post by jackpf »

Yeah, I just have the one table.

Well, you could just put

Code: Select all

setcookie('cookie_holding_id', null, -100);
on the main pae, which would, as I said, force the conversation to start from the beginning.

I don't bother caching anything...messages are sent so frequently in a chatroom I don't really see the point - it probably takes just as long to check all the files, check dates, modification times etc...

And the window.onunload thing not working isn't a huge deal...it just means that people don't get a "... has left the chatroom" message for people using firefox.

I could just as well check every now and again to see if the user is still online, with the stat tracking i have set up throughout my site...I just haven't had time to work on my IM; other stuff has taken priority.

Anyway, I'm just throwing ideas at you...it's best to have all the options before you start. Your choice though :)
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Re: php ajax chat room will increase server load?

Post by s.dot »

I've done this before and cpu usage wasn't a problem, although I never had more than 50 on at the same time. If it becomes a problem - delete messages (or archive them) after a set time period (to keep the table small) and index the table appropriately. use EXPLAIN on your queries to see what mysql is doing as queries are going to be the slow part.

Another alternative is socket connections.
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
User avatar
morris520
Forum Commoner
Posts: 60
Joined: Thu Sep 18, 2008 8:56 pm
Location: Manchester UK

Re: php ajax chat room will increase server load?

Post by morris520 »

to JAB Creations

Thanks to reply. I think the idea is to read / write cache file on the server to save connections to database. There're two issues for my concerns. One, I am not sure doing that is any faster than talking to database. Though I don't know how secure it is even if we put a htaccess to block the http request.

Combing two techniques, I think it's good to first write to the cache on the server. Once writing to database or we can clean up the cache so to save a few times read / write to the database, assuming that writing to file is a lot faster. Is this possible?
User avatar
morris520
Forum Commoner
Posts: 60
Joined: Thu Sep 18, 2008 8:56 pm
Location: Manchester UK

Re: php ajax chat room will increase server load?

Post by morris520 »

to jackpf
Thanks mate I think I've grab enough ideas before go. Will keep updating progress while doing it.
User avatar
morris520
Forum Commoner
Posts: 60
Joined: Thu Sep 18, 2008 8:56 pm
Location: Manchester UK

Re: php ajax chat room will increase server load?

Post by morris520 »

to scottayy

Delete it is not a good way while I'm trying to keep them all in the database. So I need to work out a way to read newer message.

Facebook does give you an option to say if you want to delete message. That's the sample I think.

But this is not a big problem.

I will monitor the cpu in early stage but when more people are using the site, I become worried. Just being afraid of out of control. lol
User avatar
JAB Creations
DevNet Resident
Posts: 2341
Joined: Thu Jan 13, 2005 6:44 pm
Location: Sarasota Florida
Contact:

Re: php ajax chat room will increase server load?

Post by JAB Creations »

Morris, my idea is intended to reduce the number of connections made to MySQL, performance in any other regards is subjective and it's highly likely some of the other forum members would have recommendations on how exactly to apply the idea I mentioned and they in my opinion would be better suited for suggestions on the how this approach would be applied then I could provide currently.

scottayy, how much chat history (messages open total in the main area of the chat) would you personally recommend? Are we talking like 10, 100, 10,000KB? I think the later becomes more of an issue of usability (scrolling a pixel scrolls 600,000 pixels heh).

Morris...when nothing new is in the chat what are you doing to signal a response? In example I return HTTP 204 (and for IE/Opera 1223/0 since they don't understand 204 directly) for no content and it wastes no bandwidth.
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: php ajax chat room will increase server load?

Post by jackpf »

Why send a header saying you're not going to send anything? Why not just...not send anything? :D

Surely sending a 204 header wouldn't save any bandwidth...?
User avatar
JAB Creations
DevNet Resident
Posts: 2341
Joined: Thu Jan 13, 2005 6:44 pm
Location: Sarasota Florida
Contact:

Re: php ajax chat room will increase server load?

Post by JAB Creations »

jackpf wrote:Why send a header saying you're not going to send anything? Why not just...not send anything? :D

Surely sending a 204 header wouldn't save any bandwidth...?
You're kidding, right? :dubious:

First and foremost headers aren't counted towards your bandwidth. Secondly no response == server timeout. There is a very clear and undebatable line between a timeout and HTTP 204 no content. If your script detects several timeouts in a row it would be advisable to have the script alert the user that they have either been disconnected from the internet or that the connection tot he server has been severed for whatever reason.
User avatar
morris520
Forum Commoner
Posts: 60
Joined: Thu Sep 18, 2008 8:56 pm
Location: Manchester UK

Re: php ajax chat room will increase server load?

Post by morris520 »

Guys

Anyone heard about http://xmpp.org/ and OpenFire?
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: php ajax chat room will increase server load?

Post by jackpf »

Not in any great detail. 8)

Are you able to install this stuff on your server though?
User avatar
morris520
Forum Commoner
Posts: 60
Joined: Thu Sep 18, 2008 8:56 pm
Location: Manchester UK

Re: php ajax chat room will increase server load?

Post by morris520 »

To jackpf

I am doing bit reading on this and related things now. More reading I do more interests I am getting.

It actually fit various servers as I read and I will keep updating my progress about this work.

Rather than writing it from the ground, I think it's more likely will go for integration with Openfire + Sparkweb using PHP and MySQL.
User avatar
morris520
Forum Commoner
Posts: 60
Joined: Thu Sep 18, 2008 8:56 pm
Location: Manchester UK

Re: php ajax chat room will increase server load?

Post by morris520 »

Right come back to update my progress

After my researches I found two good examples

http://www.ajaxim.com/

And Openfire, Spark.

But it comes to me as part of my requirements as:
1 - need to use push not pull technique because we are targeting quickly-increased numbers of users
2 - Try as much as possible to avoid loading server, whch seems to be a client push client procedure

This is the real thing. I thanks for all guys replied previously but now I am getting to start coding.

Anyone got the mean idea of 'push'?
User avatar
morris520
Forum Commoner
Posts: 60
Joined: Thu Sep 18, 2008 8:56 pm
Location: Manchester UK

Re: php ajax chat room will increase server load?

Post by morris520 »

Right
I am lost again. Just wondering how PUSH is better over PULL?

e.g. HTTP streamming is an implementation of PUSH. But it keeps outputing cotentents to the client (empty content when no new data ) and what is different from refreshing page at the client-side?

If we are saying Instant Messenger here, this technique will use quite a lot resource to output "new data", more likely, it outputs a lot of chunks.

If PUSH is better than PULL, why? I think asking for refreshing every 2 secs at the client side is no different from streamming every 2 secs from server to client?

Please correct me any professor!
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: php ajax chat room will increase server load?

Post by jackpf »

Well, I don't know much about this, but I've just done a bit of research.

Push will likely be the most efficient, since you don't have users requesting data when there is none - connections are only made when there is data to be sent.

However, I'm unfamiliar with "push" techniques...my ajax chat is pretty much the furthest I've ever gone with ajax :)
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: php ajax chat room will increase server load?

Post by VladSun »

morris520 wrote:If PUSH is better than PULL, why? I think asking for refreshing every 2 secs at the client side is no different from streamming every 2 secs from server to client?
The server won't PUSH every 2 seconds - it will PUSH only when there is new data to be sent.
Client will PULL every 2 seconds because it *doesn't know* whether there is new data or not.
There are 10 types of people in this world, those who understand binary and those who don't
Post Reply