3

My project is a HTTP chat using some Jquery, PHP and Mysql.

Jquery infact polls the database every N seconds to check if I have receieved new messages (polling form a mysql table).

Since chat has now >100 connections, mysql gets now 100 requests within N seconds.

What are the best practices, database choice to optimize it ? (it must remain an HTTP chat without using some server sockets)

regards

PS. Maybe MYSQL is not the good choice

yarek
  • 11,278
  • 30
  • 120
  • 219
  • Where does he say that he has to use MySQL? – BenM Dec 13 '12 at 00:15
  • @HugoDozois: He says he's using Mysql. He says he has to use HTTP. He doesn't say he has to use MySQL. – Amadan Dec 13 '12 at 00:15
  • If you're looking for speed, you may be able to leverage a noSQL solution like mongodb or cassandra – jchapa Dec 13 '12 at 00:20
  • Wouldn't Cassandra be a bit overdoing it? Any reasons to use it in such a setting? – Phil Rykoff Dec 13 '12 at 00:24
  • 3
    Why are you round tripping chat entries into a database? A socket based solution with NodeJS would probably be a lot more responsive at scale. http://nodejs.org/ – antman Dec 13 '12 at 00:33

3 Answers3

3

MySQL is fine as a database, but your polling usage of it is not best practice.
An RDBMS is the wrong tool for that job.

Look at message queue solutions. Here are some resources:

Bill Karwin
  • 538,548
  • 86
  • 673
  • 828
2

Id go with MySql since it is very light weight. PHP and MySql get along well. Since you will have many updates and many reads to the database the InnoDB engine will suite this scenario the best. You may run into problems if you choose MyIsam since it is suited for one job at a time (either updating or reading).

Luke101
  • 63,072
  • 85
  • 231
  • 359
1

Look into in-memory databases. Chats are normally not something people persist; so a transient database might be just the ticket. For instance, SQLite can do it.

However, I'd be much more worried about your web server, I think. :)

Any particular reason not to use sockets? This scenario is what they're created for. (Probably inflexible hosting service?)

Amadan
  • 191,408
  • 23
  • 240
  • 301