This week's book giveaways are in the Jython/Python and Object-Oriented programming forums.
We're giving away four copies each of Machine Learning for Business: Using Amazon SageMaker and Jupyter and Object Design Style Guide and have the authors on-line!
See this thread and this one for details.
Win a copy of Machine Learning for Business: Using Amazon SageMaker and JupyterE this week in the Jython/Python forum
or Object Design Style Guide in the Object-Oriented programming forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Paul Clapham
  • Jeanne Boyarsky
  • Knute Snortum
Sheriffs:
  • Liutauras Vilda
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Joe Ess
  • salvin francis
  • fred rosenberger

Prioritize user request

 
Ranch Hand
Posts: 196
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Firstly, I'm sorry if I posted to a wrong place as I don't where it should fit.
My question is if I have a web resource, says a JSP page, and I'd like to give priority to certain user to access the page.
i.e. paid user will have faster access than anonymous user
How can I achieve it?
I've read an article on this sometime back but couldn't recall anymore.
I'd appreciate anyone can advice how this is achieved and also, if this is under "Load balancing", "Request filtering", or .....
Thanks for any advice.
Cheers.

Han Ming
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How about setting the priority of the thread executing the request:

Bill
 
Author
Posts: 111
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Original question:

My question is if I have a web resource, says a JSP page, and I'd like to give priority to certain user to access the page.
i.e. paid user will have faster access than anonymous user
How can I achieve it?


Suggested solution:


How about setting the priority of the thread executing the request:


Well, it is hard to know what the original user wanted, but I'm not so sure this thread-priority idea will work very well.
First of all, my general rule of thumb for multithreaded programming is "Don't use thread priorities to control execution speed." That's because the Thread spec is deliberately vague about scheduling algorithms (to allow for OS-specific optimizations). In practice, many schedulers do NOT follow the practice that all OS's follow for user priorities, namely that all threads make SOME progress. Many just run higher-priority threads in lieu of lower-priority ones, except when the higher-priority ones are waiting on I/O. So, increasing a thread's priority could result in it taking over the whole server. Decreasing it could prevent it from ever running at all. Of course, I'm being paranoid here since there is lots of I/O going on. Still, on a heavily-loaded server, this could be a problem: the unpaying customers might NEVER run.
Second, what if the load is light? The original user didn't say, but I got the impression that unpaid users should still run slowly. With Thread priorities, they'd run just as fast when NO higher-priority threads were around.
Third, in many apps, the only thing that really matters is how long the database call takes. So, slowing down or speeding up the main thread wouldn't make any difference if the database call takes the same amount of time.
So, if that behavior is really what you want, maybe just do a few small Thread.sleep calls in the unpaid user's response? A Filter could apply this behavior universally without putting that logic in each page separately.
Cheers-
- Marty
 
Please enjoy this holographic presentation of our apocalyptic dilemma right after this tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!