Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6997449
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T20:17:06+00:00 2026-05-27T20:17:06+00:00

The system I work is a little more complex to explain here but I

  • 0

The system I work is a little more complex to explain here but I can reduce it to something more simple.

Let’s say I have a simple chat server and I count the seconds every client stays connected and save it in a table(I’m using mysql).
So every time a client connects I save the time he stays connected in seconds (int)
If he disconnects and connects again I save this info in another row because this is how I want. The number of times a client connects to the server in a day is between 50k-500k or even more(I know, I know but this is related to my complex system but irrelevant to my question here).

My problem is that I want to show to every client some stats about his visits similar to google analytics(by days), to be more specific I’m interested in showing the average time he spent on a certain day.

I’m looking at an optimized way to do this. So far I’ve thought about the following solutions:

  1. use select avg(time) from table where date=…. but speed problems might occur

  2. save the avg time in a separate table for every day and user. This solutions is ok, but raises another question: how do I save the average time? here are the situations I was thinking:

a) use mysql trigger to update the stats every time a client is connecting (using INSERT AFTER …) this solution is not bad, however like I said the client can connect 500k times/day which means 500k times mysql needs to calculate the average time

b) make a separate application similar to a cron job or a timer task that updates the stats every X hours ,this way I know the mysql server will be used only once a few hours depending on the number of clients I have.

So far I’m thinking of implementing the 2.b solution, but I said to ask you first before proceeding. If you have better ideas please share.

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T20:17:06+00:00Added an answer on May 27, 2026 at 8:17 pm

    You can use solution a but don’t recalculate the average over and over again. You can do it by storing the current average and the amount of items that where used to calculate the average. Your formula would be like:

    (current_average*number_of_old_items+new_value)/(number_of_old_items+1)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The system I work on here was written before .net 2.0 and didn't have
Now I'm trying to work with System.Web.Routing. All is just fine, but I can't
I'm writing a simple document management system for my work. I'm only a hobbyist
I have a very complex system (100+ threads) which need to send email without
We have a situation at work where developers working on a legacy (core) system
To be a little more specific: I've built a simple multithreaded TCPServer (Java) which
Let's say i have 2 files located in the same folder. /Test/View.cshtml <h1>File that
I have written a nice little Firefox Add-On for the company I work for
The system I work with is creating a whole lot of objects and garbage
Hey guys i am trying to automate my system at work for sending artwork

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.