473,804 Members | 3,722 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Max Simultaenous requests based on Date/Time

2 New Member
Hi,

I have a table in which i have the information about actions along with the date/time when the action happened. I want to know maximum simultaneous requests for a given action at any given time.

Example: Users signing into web site. Here is some sample data (using integers at timestamps to keep the example simple) :

1. User A logs in at time 0.
2. User B logs in at time 0.
3. User C logs in at time 1.
4. User D logs in at time 3.
5. User A logs out at time 4.
6. User E, F and G logs in at time 5.
7. User C logs out at time 6.
8. All Users log out at time 7.

Now, I want to run a query on start time = 0, end time = 7 and I want to know what was the maximum simultaneous count for the number of users logged in?

Based on the data, the user/time distribution is:
time 0: 2 users
time 1: 3 users
time 2: 3 users
time 3: 4 users
time 4: 3 users
time 5: 6 users
time 6: 5 users
time 7: 0 users

and so, max. simultaneous users between 0 and 7 is 6 (at time = 5). How can I find this using SQL query?

Table structure:
1. Each row has log-in and log-out time.
2. Record is written to the table once user logs-out. Till that time, its kept in memory. (Changing this behavior is not an option right now).

You can assume that this table only stores log-in and log-out actions.
Aug 4 '07 #1
3 1886
pbmods
5,821 Recognized Expert Expert
Heya, ataulhaq. Welcome to TSDN!

The problem with trying to do this with a query is that you always have to start from time 0 or else your count might not be valid.

For example, if there are two Users logged in at time 0, but you start counting with time 2, your result set will always be off by two Users.

And what happens after your site has been around for awhile, and you want to get the max. simultaneous logins up to time 1,500,000?

The easiest way to accomplish this would be to create a counter that keeps track of the number of Users that are logged in and then saving it with each entry in the table.

E.g.,
Expand|Select|Wrap|Line Numbers
  1. SELECT
  2.         MAX(`UserCount`)
  3.     FROM
  4.         `LoginActivity`
  5.     WHERE
  6.         `Time` BETWEEN 0 AND 7
  7.     GROUP BY
  8.         `Time`
  9.  
Now, the *real* fun kicks in when your Users don't log themselves out when they're done using your site....
Aug 5 '07 #2
ataulhaq
2 New Member
Heya, ataulhaq. Welcome to TSDN!

The problem with trying to do this with a query is that you always have to start from time 0 or else your count might not be valid.

For example, if there are two Users logged in at time 0, but you start counting with time 2, your result set will always be off by two Users.

And what happens after your site has been around for awhile, and you want to get the max. simultaneous logins up to time 1,500,000?

The easiest way to accomplish this would be to create a counter that keeps track of the number of Users that are logged in and then saving it with each entry in the table.

E.g.,
Expand|Select|Wrap|Line Numbers
  1. SELECT
  2.         MAX(`UserCount`)
  3.     FROM
  4.         `LoginActivity`
  5.     WHERE
  6.         `Time` BETWEEN 0 AND 7
  7.     GROUP BY
  8.         `Time`
  9.  
Now, the *real* fun kicks in when your Users don't log themselves out when they're done using your site....
Hi,

Well, the counts may have created the situation more confusiong. The real data in database has date/time stamps. I just didn't want to write the whole timestamp and so used counts.

So, the comment regarding starting from count 0 may not be applicable since the query would be between two timestamps always. Like I want to know maximum number of users between 2007-06-01 10:00:00 and 2007-06-03 10:00:00.

I agree with the counter approach and that is what we are planning for but I was just wondering if there is a way we can do it using SQL. We do have a solution to it but it is not pure SQL. We get two results sets. One for log-in time and one for log out time and we merge both sets and sort it. So for every log in, we increment the count and for every log out we decrement it. The maximum count is the max simultaneous users within given time period.
Aug 6 '07 #3
pbmods
5,821 Recognized Expert Expert
Heya, ataulhaq.

The issue with doing this using a query is that you have to take into account the number of Users who were logged in before you start calculating.

For example, assume 2 Users logged in at 2007-05-31 13:45:00 and 2007-05-31 13:45:05, respectively.

Here's where the problem occurs:
Expand|Select|Wrap|Line Numbers
  1. SELECT
  2.     .
  3.     .
  4.     .
  5.     WHERE
  6.         `datetime` BETWEEN '2007-06-01 00:00:00' AND '2007-06-30 11:59:59'
  7.  
Notice that the number of active Users on June 1st will be at least two off because it won't take into account the two Users who logged in on May 31st without logging off.

And if the Users that were logged in on May 31st then log out on June 1st, your User count might even be negative!

I think your best bet is to either update a counter on login/logout, or you can do what phpBB does, but you'll have to combine it with a periodic script (such as cron, or by implementing a cron script and hope your traffic is frequent).

The way phpBB does it is the database stores the timestamp of the last action taken by the User (i.e., every time the User sends a request, the timestamp updates).

Then, to find out the number of *active* Users, simply count the number of timestamps greater than 15 minutes ago.

To get a history of this value, you'd need to run a script once per day and count (and index) the number of timestamps greater than 1 day ago.

The counter idea is probably easier, though the 'active' counter is probably a better benchmark.
Aug 6 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

0
1515
by: Fritz Bosch | last post by:
We are in the process of refactoring our GUI-based test application for radio equipment and are rewriting a significant part in Python. The new architecture will substantially be based on the model-view-controller pattern, as follows: User Input | v +-------------+ service request service request +-------------+
4
2636
by: Richard Cornford | last post by:
For the last couple of months I have been trying to get the next round of updates to the FAQ underway and been being thwarted by a heavy workload (the project I am working on has to be finished an QA tested for a new year release. I don't think that going to prove practical, but there is no harm in trying :) and some serious family commitments. But it has to be done soon so this is stage one. Mike Winter provided an extensive list of...
3
2102
by: Bond | last post by:
how do I know when the browser is making a request to the server? I am not having an onclick event for EVERY hyperlink, submit, etc. There must be some javascript function that I can overwrite that will allow me to do something when the browser requests something from the server. My plan is whenever a browser is about to request something from the server to create a time stamp and then compare this time to the time when the page...
1
3308
by: Dominic | last post by:
Hi all, We've just migrated to IIS 6.0 / Windows Server 2003. We are now experiencing some stability problem what we did not experience in IIS 5.0 / Windows 2000 Server. Our ASP.NET application is running in a web-farm environment of multiple web servers. We have been using "Performance Monitor" to monitor the "Requests in Application Queue" counter of "ASP.NET Apps v.1.1.4322" object. We have found the following pattern.
2
2845
by: Peter McEvoy | last post by:
Folks, I've been building a Webservice API for a contract that will be exposed to the internet at large. There are two endpoints, and each endpoint contains a number of webmethods. Every webmethod returns a returncode which indicates the level of success in performing the operation (as well as the actual results of the call in an "out" parameter) They have a requirement that when they want to perform maintenance on the backend system,...
5
2574
by: linda.chen | last post by:
Hi all, We have a webservice (service1), which calls another webservice(service2) from another orginization. Our end users make requests throught service1. When service2 receives a quest, it puts all the request information into a database. The request will be picked up from a sheduler which is installed in 8 different servers. The response is very slow if we have many requests.
6
9558
by: trytobreak | last post by:
Hi All, I am a network administrator in a fairly large software company and I would like to write myself a small utility, which would connect (one by one) to all machines on the network and get their current date and time stamps. This is mostly because of coming DST changes and having hundreds of machines on the network, I don't want to connect remotely to every and each server to see if the time is correct.
3
4049
by: =?Utf-8?B?QmlsbHkgWmhhbmc=?= | last post by:
I want to limit the user only login the system one time at the same time. I don't want him login the system two with the same user at the same time. How to do this? If i have a table to record if this user has logined, this user didn't logout and just close IE, how do i set his recoed in the table logout? Thanks, -Billy
0
9569
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10318
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10302
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9130
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7608
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6844
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5636
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4277
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3802
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.