P
P
pasha00112022-03-20 20:00:38
Database design
pasha0011, 2022-03-20 20:00:38

How to calculate the maximum load on the database?

Situation:

Arranging a raffle.
According to the terms of the draw, after completing the main task, the participant is given 1 lottery ticket.

Lottery_ticket_id is generated in the database and this id is associated with the lottery_participant_id.
When drawing - we put a random number from the number 1 to the number of the last id_lottery_ticket
And thus we understand who won the prize.

For each person invited to the drawing by referral link, the participant of the drawing receives the same number of lottery tickets as he currently has.
1x2 ticket total 2 tickets, then for each new invited referral, the participant will receive 2,4,8,16,32, etc.

But there is a problem!
When the participant of the draw invites the 21st person, he will receive 1.048.576 lottery tickets.

It is necessary to generate and write 1 million lines to the database in the format:
id_lottery_ticket
id_participant_of the lottery

actually the question is, how to calculate how much this operation will consume resources ?
so that later it would be possible to understand how much time would be needed on a particular hardware to perform this operation.

maybe I’m thinking in the wrong direction at all and there are some other solutions how this can be done)
_____________________________________
about removing x2 and adding a fixed "reward" - this is possible, but this will kill the motivation of participants to invite friends. as with each invitation, the stakes grow and the excitement grows.
there are a lot of variations on how this can be changed ... for example, leave X2 to a certain value, or give 10 tickets more than last time ...

but the main question is how can you calculate the load on resources)

Answer the question

In order to leave comments, you need to log in

3 answer(s)
R
Rsa97, 2022-03-20
@Rsa97

The chance of winning is not determined by the number of tickets, but solely by their number. So there is no point in generating and storing numbers. It is enough to add the required number of tickets to the user.

R
rPman, 2022-03-20
@rPman

the number of a lottery ticket can be issued by some deterministic algorithm that generates a number according to its position
, then the user can store ticket numbers at intervals (tickets with numbers a + n ... a + n * 2 are issued), the list of lottery tickets itself is not necessary to store in the database,
for the time of distribution, a service is spinning that distributes numbers sequentially (at intervals), even if it wastes memory for this, some kind of semi-recursive permutation algorithm, in fact, this is the question of how to beautifully implement it
, but writing 2 ^ 100500 numbers into the database is unreasonable waste of resources.

D
Dr. Bacon, 2022-03-20
@bacon

All calculations will be very approximate, so you can make a mistake by orders of magnitude. This is only load testing, and even with it you can make a mistake by creating the wrong load profile, but nevertheless, this will be the closest option to the real one. Do not forget that in addition to the database itself, there is also a higher level, an application on which you can also create a significant load.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question