Dharanesh
Dharanesh

Reputation: 21

What exactly Peak Concurrent User means

what exactly PCU refer? I have data like this can anyone tell me from this data what would be the result for peak concurrent users? How to calculate PCU using sql query according to this data? enter image description here

Upvotes: 0

Views: 1496

Answers (2)

MatBailie
MatBailie

Reputation: 86775

Assuming you have access to Window Functions / Analytic Functions...

SELECT
    MAX(concurrent_users)   AS peak_concurrent_users
FROM
(
    SELECT
        SUM(CASE WHEN event = 'logout' THEN -1 ELSE 1 END)
            OVER (ORDER BY __time, user_id, event)
                AS concurrent_users
    FROM
        yourTable
    WHERE
        event IN ('login', 'logout')
)
    AS running_total

This just adds up how many people have logged in or out in time order, and keeps a running total. When someone logs in, the number goes up, when someone logs out, the number goes down.

Where two events happen at exactly the same time, it assumes the lowest user_id actually went first. And if a user has a login and logout at exactly the same time, it assumes the login actually went first.

Upvotes: 1

AntG
AntG

Reputation: 1294

PCU would mean the maximum number of users logged in at the same time during a given time period.

In your data you only have two users, so it can never be more than 2. We can see that at times, both users are logged in at the same time, so PCU=2 for this data.

Upvotes: 1

Related Questions