Discussion:
pick a number from 1 to 10
(too old to reply)
rodchar
2009-12-19 18:01:01 UTC
Permalink
hey all,

i want to create an asp.net web page that allows internet users to pick a
number from 1 to 10. how do i manage users picking the same number? (if 2
users somewhere happen to be selecting the same number and the same time). Is
this a concurrency issue?

thanks,
rodchar
Stefan Hoffmann
2009-12-19 18:49:11 UTC
Permalink
hi Rodchar,
Post by rodchar
i want to create an asp.net web page that allows internet users to pick a
number from 1 to 10.
You may use ten links or buttons. But what should happens after they
"picked" a number?
Post by rodchar
how do i manage users picking the same number? (if 2
users somewhere happen to be selecting the same number and the same time). Is
this a concurrency issue?
Why do you want to do that?


mfG
--> stefan <--
rodchar
2009-12-19 19:33:01 UTC
Permalink
Post by Stefan Hoffmann
You may use ten links or buttons. But what should happens after they
"picked" a number?
I just want to make sure the first 10 users that select a number and that
each user has a unique number
Post by Stefan Hoffmann
Why do you want to do that?
I want to make it a game.
Post by Stefan Hoffmann
hi Rodchar,
Post by rodchar
i want to create an asp.net web page that allows internet users to pick a
number from 1 to 10.
You may use ten links or buttons. But what should happens after they
"picked" a number?
Post by rodchar
how do i manage users picking the same number? (if 2
users somewhere happen to be selecting the same number and the same time). Is
this a concurrency issue?
Why do you want to do that?
mfG
--> stefan <--
.
Peter Duniho
2009-12-19 19:41:44 UTC
Permalink
Post by rodchar
Post by Stefan Hoffmann
You may use ten links or buttons. But what should happens after they
"picked" a number?
I just want to make sure the first 10 users that select a number and that
each user has a unique number
Then yes, you will have to have _some_ mechanism to ensure that each
user cannot pick the same number some other user does.

But since you are trying to implement this in an ASP.NET project, you
need to post your question in the ASP.NET newsgroup. Your concurrency
issues are specific to ASP.NET and thus you will only get the best
answer to your question posting it there.

Pete
rodchar
2009-12-19 23:53:01 UTC
Permalink
thanks all for the help,
rod.
Post by Peter Duniho
Post by rodchar
Post by Stefan Hoffmann
You may use ten links or buttons. But what should happens after they
"picked" a number?
I just want to make sure the first 10 users that select a number and that
each user has a unique number
Then yes, you will have to have _some_ mechanism to ensure that each
user cannot pick the same number some other user does.
But since you are trying to implement this in an ASP.NET project, you
need to post your question in the ASP.NET newsgroup. Your concurrency
issues are specific to ASP.NET and thus you will only get the best
answer to your question posting it there.
Pete
.
Arne Vajhøj
2009-12-20 22:12:37 UTC
Permalink
Post by Peter Duniho
Post by rodchar
Post by Stefan Hoffmann
You may use ten links or buttons. But what should happens after they
"picked" a number?
I just want to make sure the first 10 users that select a number and
that each user has a unique number
Then yes, you will have to have _some_ mechanism to ensure that each
user cannot pick the same number some other user does.
But since you are trying to implement this in an ASP.NET project, you
need to post your question in the ASP.NET newsgroup. Your concurrency
issues are specific to ASP.NET and thus you will only get the best
answer to your question posting it there.
The concurrency issues are not ASP.NET specific.

They are the same whether it is browser--(HTML/HTTP)--web app,
fat client--(SOAP/HTTP)-- web service,
fat client--(binary/socket)--server or something else.

Arne
Peter Duniho
2009-12-21 20:00:00 UTC
Permalink
Post by Arne Vajhøj
The concurrency issues are not ASP.NET specific.
Sure they are. The mere fact that it's an ASP.NET application
guarantees that.

In a C# program, the solution is trivial. But in ASP.NET, there's no
guarantee AFAIK that every client being serviced is being handled by the
same process.

If nothing else, the fact there's no way for someone unfamiliar with
ASP.NET to know for sure that every client is being serviced by the same
process makes the question ASP.NET-specific, even if the answer turns
out to be the same.

Pete
J.B. Moreno
2009-12-22 01:18:56 UTC
Permalink
Post by Peter Duniho
Post by Arne Vajhøj
The concurrency issues are not ASP.NET specific.
Sure they are. The mere fact that it's an ASP.NET application
guarantees that.
In a C# program, the solution is trivial. But in ASP.NET, there's no
guarantee AFAIK that every client being serviced is being handled by the
same process.
Really? How do you prevent two users from logging on to a server and
running the same application and picking the same number at the same
time?

Or if the application is deployed to a share, how do you prevent two
users from two different machines running the same application and...
--
J.B. Moreno
Peter Duniho
2009-12-22 01:59:47 UTC
Permalink
Post by J.B. Moreno
Post by Peter Duniho
Post by Arne Vajhøj
The concurrency issues are not ASP.NET specific.
Sure they are. The mere fact that it's an ASP.NET application
guarantees that.
In a C# program, the solution is trivial. But in ASP.NET, there's no
guarantee AFAIK that every client being serviced is being handled by the
same process.
Really? How do you prevent two users from logging on to a server and
running the same application and picking the same number at the same
time?
I don't understand your question. The "how do you..." question is
exactly my point. AFAIK, nothing in ASP.NET _does_ guarantee that.
Surely there are specific ways using ASP.NET to provide for that
guarantee (such as using a database as Arne suggested, or having a
special-purpose server process shared among all clients), but those ways
will necessarily be specific to ASP.NET.

Frankly, your question simply reinforces my point: if one knows in
advance one is dealing with a single process, the question is simple to
answer. But with ASP.NET in the picture, it gets a bit different, and
in a way that is specific to ASP.NET.
Post by J.B. Moreno
Or if the application is deployed to a share, how do you prevent two
users from two different machines running the same application and...
What's that got to do with ASP.NET, or the original question for that
matter?
J.B. Moreno
2009-12-22 07:02:02 UTC
Permalink
Post by Peter Duniho
Post by J.B. Moreno
Post by Peter Duniho
Post by Arne Vajhøj
The concurrency issues are not ASP.NET specific.
Sure they are. The mere fact that it's an ASP.NET application
guarantees that.
In a C# program, the solution is trivial. But in ASP.NET, there's no
guarantee AFAIK that every client being serviced is being handled by the
same process.
Really? How do you prevent two users from logging on to a server and
running the same application and picking the same number at the same
time?
I don't understand your question. The "how do you..." question is
exactly my point. AFAIK, nothing in ASP.NET _does_ guarantee that.
And nothing would guarantee it if it was a WinForm application deployed
to a Windows 2008 server.

Which is the point, the issue isn't windows versus ASP, but
multi-process versus single. The problem isn't ASP specific, and the
solution is unlikely to be ASP specific.
Post by Peter Duniho
Surely there are specific ways using ASP.NET to provide for that
guarantee (such as using a database as Arne suggested, or having a
special-purpose server process shared among all clients), but those ways
will necessarily be specific to ASP.NET.
Using a database isn't ASP.NET specific. Neither is having a separate
process to act as a middle man.
Post by Peter Duniho
Frankly, your question simply reinforces my point: if one knows in
advance one is dealing with a single process, the question is simple to
answer. But with ASP.NET in the picture, it gets a bit different, and
in a way that is specific to ASP.NET.
C# and no ASP.NET does not exclude multiple processes.
Post by Peter Duniho
Post by J.B. Moreno
Or if the application is deployed to a share, how do you prevent two
users from two different machines running the same application and...
What's that got to do with ASP.NET, or the original question for that
matter?
It shows that the problem is multiple processes running at the same
time, not whether it's a ASP.NET process or console application.

The solution is to create a choke point of some kind, and again that
isn't necessarily ASP specific.

While this isn't a syntax problem, neither the problem nor the solution
require ASP.NET.
--
J.B. Moreno
Peter Duniho
2009-12-22 10:04:07 UTC
Permalink
Post by J.B. Moreno
And nothing would guarantee it if it was a WinForm application deployed
to a Windows 2008 server. [...]
That depends on the deployment. But if the deployment is specifically
some sort of server context where something outside the C# program is
somehow creating the potential for multiple processes, then the answer
to that question is STILL outside the scope of this newsgroup.

Because the OP is using ASP.NET, I suggested the ASP.NET newsgroup.
That is a newsgroup where server issues are very much on-topic while
still being specifically connected to the actual API the OP is using,
and the OP will find much greater expertise than here.

You may want to argue that the OP would be even better served by a forum
that is even more specifically about deploying server-side
implementations than the ASP.NET newsgroup. That seems like a fine
point, and it might be true. But there's no justification at all for
suggesting that the topic has anything to do with C# specifically, and
even suggesting it's a normal .NET topic is a stretch.

Pete
J.B. Moreno
2009-12-23 08:01:04 UTC
Permalink
Post by Peter Duniho
Post by J.B. Moreno
And nothing would guarantee it if it was a WinForm application deployed
to a Windows 2008 server. [...]
That depends on the deployment. But if the deployment is specifically
some sort of server context where something outside the C# program is
somehow creating the potential for multiple processes, then the answer
to that question is STILL outside the scope of this newsgroup.
He wants to solve a problem, he wants to solve that problem using C#.
Unless the scope of the newsgroup is limited to just questions about
syntax, it's well within the scope of the group.

The OP asked "how do i manage users picking the same number?" -- he is
asking guidance for methodology, no different than asking what design
pattern to use.

He should be told that there are two possibilities: either an error
message when submitting a choice that has already been picked, or
blocking other users from making a choice while giving a particular
user a chance/timeframe to make a decision from the available options.

I am *certain* that you could write a class/interface for doing either
possibility that in no way relied upon the internal workings of
ASP.NET.
--
J.B. Moreno
RayLopez99
2009-12-23 15:12:08 UTC
Permalink
Post by J.B. Moreno
I am *certain* that you could write a class/interface for doing either
possibility that in no way relied upon the internal workings of
ASP.NET.
Yes, you are correct and Peter Dumbo is wrong, as often the case.
Peter is very brittle and often breaks. But he is useful, and I
appreciate his posts, so don't get me wrong.

A singleton indeed is a kludgy but practical design pattern for this
problem.

RL
Peter Duniho
2009-12-23 19:29:40 UTC
Permalink
Post by J.B. Moreno
[...]
I am *certain* that you could write a class/interface for doing either
possibility that in no way relied upon the internal workings of
ASP.NET.
I amused that so far, no one has bothered to do so.

Please, show us the code that can be used in an ASP.NET project to
address the specific question, and which works regardless of whether
it's in an ASP.NET project at all, never mind how that ASP.NET project
is deployed.

Pete
Arne Vajhøj
2010-01-04 01:59:50 UTC
Permalink
Post by Peter Duniho
Post by J.B. Moreno
[...]
I am *certain* that you could write a class/interface for doing either
possibility that in no way relied upon the internal workings of
ASP.NET.
I amused that so far, no one has bothered to do so.
Please, show us the code that can be used in an ASP.NET project to
address the specific question, and which works regardless of whether
it's in an ASP.NET project at all, never mind how that ASP.NET project
is deployed.
Two methods has been proposed:
* single node using ordinary memory synchronization
* multinode using database

Are you saying that you can not implement those without
referencing anything ASP.NET ??????????

Arne
Peter Duniho
2010-01-04 05:22:20 UTC
Permalink
Post by Arne Vajhøj
* single node using ordinary memory synchronization
Works only in-proc and does not deal with a multi-proc scenario (which
is possible for an ASP.NET project).
Post by Arne Vajhøj
* multinode using database
That's true…I forgot it had been mentioned. But it's not the kind of
thing someone NOT doing this in the context of ASP.NET would choose.

Anyway, I know your habits…you can't let this go, and you will swear up
and down until the cows come home that the OP doesn't have an ASP.NET
question. Fine by me. I won't agree, but I'll stop trying to convince
you otherwise (as if there had ever been any chance of doing so in the
first place).

Pete
Arne Vajhøj
2010-01-04 01:56:28 UTC
Permalink
Post by J.B. Moreno
And nothing would guarantee it if it was a WinForm application deployed
to a Windows 2008 server. [...]
That depends on the deployment. But if the deployment is specifically
some sort of server context where something outside the C# program is
somehow creating the potential for multiple processes, then the answer
to that question is STILL outside the scope of this newsgroup.
No.

Server side programming is on topic here.
Because the OP is using ASP.NET, I suggested the ASP.NET newsgroup. That
is a newsgroup where server issues are very much on-topic while still
being specifically connected to the actual API the OP is using, and the
OP will find much greater expertise than here.
He will most likely be told that it is off topic there, because it
has nothing to do with ASP.NET.
You may want to argue that the OP would be even better served by a forum
that is even more specifically about deploying server-side
implementations than the ASP.NET newsgroup. That seems like a fine
point, and it might be true. But there's no justification at all for
suggesting that the topic has anything to do with C# specifically, and
even suggesting it's a normal .NET topic is a stretch.
Given that he wants to actually wants to implement this code in C#
I would consider it on topic.

Otherwise it would be a very low traffic group.

Arne
RayLopez99
2009-12-22 21:06:14 UTC
Permalink
Post by J.B. Moreno
While this isn't a syntax problem, neither the problem nor the solution
require ASP.NET.
OK you got me--that's true. You cannot guarantee, unless you use
GUIDs, that two users will not pick the same two numbers. But one
simple solution is indeed to use GUIDs. Assign each number to a GUID,
first come, last served. This is simply an UPDATE problem in SQL.
You can have "LAST IN WINS" (the default) in the case two users are
online at the same time and pick the same number.

But, if you don't want the default (LAST IN WINS) be aware it's a lot
of work. I got tangled up in it myself and could not make it work.
So I switched to LAST IN WINS for the odd case where two users are
online at the same time and pick the same number. As a practical
matter that's rare anyway, unless you have 1000s of users online at
the same time. But I digress.

RL
Arne Vajhøj
2010-01-04 01:46:45 UTC
Permalink
Post by Arne Vajhøj
The concurrency issues are not ASP.NET specific.
Sure they are. The mere fact that it's an ASP.NET application guarantees
that.
No.

The same concurrency issues exist in non-ASP.NET contexts.

That makes it non-ASP.NET specific.
In a C# program, the solution is trivial.
No.

It is only trivial in a C# desktop app.

It is non trivial in all server contexts no matter whether
it is a ASP.NET web app or a WCF web service or Windows
service acting as socket server or a console app
acting as socket server.
But in ASP.NET, there's no
guarantee AFAIK that every client being serviced is being handled by the
same process.
True.

But there are no guarantee in any other context except the most trivial.

And C# is more than desktop apps.
If nothing else, the fact there's no way for someone unfamiliar with
ASP.NET to know for sure that every client is being serviced by the same
process makes the question ASP.NET-specific, even if the answer turns
out to be the same.
Any programmer above beginner level would consider this a problem
best handled in the BLL completely unrelated to the choice of PL.

Making ASP.NET as PL completely irrelevant.

Arne
Stefan Hoffmann
2009-12-20 13:11:17 UTC
Permalink
hi,
Post by rodchar
Post by Stefan Hoffmann
You may use ten links or buttons. But what should happens after they
"picked" a number?
I just want to make sure the first 10 users that select a number and that
each user has a unique number
Use the singelton pattern to create this kind of manager and ensure that
your application runs only in one AppDomain on the IIS.

http://msdn.microsoft.com/en-us/library/ms998558.aspx
http://msdn.microsoft.com/en-us/library/ms178473.aspx
http://msdn.microsoft.com/en-us/library/cxk374d9%28VS.71%29.aspx


mfG
--> stefan <--
Arne Vajhøj
2009-12-20 22:08:35 UTC
Permalink
Post by Stefan Hoffmann
Post by rodchar
Post by Stefan Hoffmann
You may use ten links or buttons. But what should happens after they
"picked" a number?
I just want to make sure the first 10 users that select a number and that
each user has a unique number
Use the singelton pattern to create this kind of manager and ensure that
your application runs only in one AppDomain on the IIS.
And cross fingers that the load will never be so big that clustering
is needed.

Arne
Peter Duniho
2009-12-21 20:00:45 UTC
Permalink
Post by Arne Vajhøj
And cross fingers that the load will never be so big that clustering
is needed.
Would clustering result in multiple processes being handled by multiple
processes? If so, I _really_ am boggled by your assertion that the
concurrency issues are not ASP.NET-specific.
Peter Duniho
2009-12-21 20:32:43 UTC
Permalink
Post by Peter Duniho
Post by Arne Vajhøj
And cross fingers that the load will never be so big that clustering
is needed.
Would clustering result in multiple processes being handled by multiple
processes? If so, I _really_ am boggled by your assertion that the
concurrency issues are not ASP.NET-specific.
"multiple processes being handled by multiple process" should, of
course, read "multiple clients being handled by multiple processes"
Arne Vajhøj
2010-01-04 01:49:47 UTC
Permalink
Post by Peter Duniho
Post by Arne Vajhøj
And cross fingers that the load will never be so big that clustering
is needed.
Would clustering result in multiple processes being handled by multiple
processes?
Yes. That would mean different processes on different systems.
Post by Peter Duniho
If so, I _really_ am boggled by your assertion that the
concurrency issues are not ASP.NET-specific.
I believe that you are boggled.

But clustering is not an ASP.NET specific concept.

Arne
Stefan Hoffmann
2009-12-21 20:12:19 UTC
Permalink
hi Arne,
Post by Arne Vajhøj
Post by Stefan Hoffmann
Post by rodchar
I just want to make sure the first 10 users that select a number and that
each user has a unique number
Use the singelton pattern to create this kind of manager and ensure that
your application runs only in one AppDomain on the IIS.
And cross fingers that the load will never be so big that clustering
is needed.
Indeed, but then, picking one number from only ten makes no sense at all ;)


mfG
--> stefan <--
Arne Vajhøj
2010-01-04 01:51:37 UTC
Permalink
Post by Stefan Hoffmann
Post by Arne Vajhøj
Post by Stefan Hoffmann
Post by rodchar
I just want to make sure the first 10 users that select a number and that
each user has a unique number
Use the singelton pattern to create this kind of manager and ensure that
your application runs only in one AppDomain on the IIS.
And cross fingers that the load will never be so big that clustering
is needed.
Indeed, but then, picking one number from only ten makes no sense at all ;)
Not if it is the only thing it does and it is always just 10.

Arne
RayLopez99
2009-12-20 14:04:46 UTC
Permalink
Post by rodchar
hey all,
i want to create an asp.net web page that allows internet users to pick a
number from 1 to 10. how do i manage users picking the same number? (if 2
users somewhere happen to be selecting the same number and the same time). Is
this a concurrency issue?
thanks,
rodchar
FIFO. That's not a concurrency problem. First number picked gets
withdrawn from the pool.

You stupid or what?

Thanks for posting here. Back to skool for u.

RL
Arne Vajhøj
2009-12-20 22:00:31 UTC
Permalink
Post by RayLopez99
You stupid or what?
Thanks for posting here. Back to skool for u.
Someone needs to go back to school!

:-)

Arne
Mark Rae [MVP]
2009-12-20 22:37:26 UTC
Permalink
Post by RayLopez99
Back to skool for u.
Your need for basic education is by far the greater...
--
Mark Rae
ASP.NET MVP
http://www.markrae.net
Arne Vajhøj
2009-12-20 22:07:21 UTC
Permalink
Post by rodchar
i want to create an asp.net web page that allows internet users to pick a
number from 1 to 10. how do i manage users picking the same number? (if 2
users somewhere happen to be selecting the same number and the same time). Is
this a concurrency issue?
If it would be a problem having two users pick the same number, then
you will have a concurrency problem.

The two standard mechanisms for this is:
1) a user that comes in locks all the numbers and other users
must wait until the first user has made a pick and then
that number is not available any more
2) you allow users to pick numbers in parallel, but users that
pick a number already picked will get an error telling them
that someone else just took that number and they have to
pick another

You can do it either in memory using standard synchronization
(lock keyword in C#) or using a database with good transaction
support. The last option supports clustering.

Arne
vanderghast
2009-12-29 19:14:57 UTC
Permalink
You also have to define what is "at the same time". Would it be like a book
you borrow, it is 'picked' as long as the borrower does not give it back?
or would it mean something like "in the same interval of time of some clock
tic" (ie. it is ok for two users to take number 2 as long as they do it not
at the same clock tic). I assume it is possible to have a common
centralized 'registry' (database, like, easier to share between many than
memory (buffer) assigned to a 'standard' process), else I fail to see who
can access the relevant history. The solution also depends on what you want
to do? simply DETECT the contention? if so, the first case can be solve if
you keep the history of in-s and out-s for each item (or the whole history),
and in the second case, the same, but force a check-in (terminate all
pending 'choices' that have not checked-out yet) at the start of each of
your clock tic (which I assume is still large enough to allow your code to
execute many operations).

But overall, the problem is quite fuzzy.

Vanderghast, Access MVP
Post by rodchar
hey all,
i want to create an asp.net web page that allows internet users to pick a
number from 1 to 10. how do i manage users picking the same number? (if 2
users somewhere happen to be selecting the same number and the same time). Is
this a concurrency issue?
thanks,
rodchar
k***@icloud.com
2018-01-26 02:47:53 UTC
Permalink
Post by rodchar
hey all,
i want to create an asp.net web page that allows internet users to pick a
number from 1 to 10. how do i manage users picking the same number? (if 2
users somewhere happen to be selecting the same number and the same time). Is
this a concurrency issue?
thanks,
rodchar
Loading...