kek.
when a user types text, sleep using a
setTimeout / clearTimeout combination to delay sending the query to the database every single time. this will help buffer your load to the database. 100-300ms should work;
two user statistics can be done from a simple approach, one show the 24 hours like you used to; still useful, but say it was 24 hours, then add another for the last 5 minutes. This is easy if you have a timestamp on the session database; usually I select count() if it is >= time() - 300