Author Topic: Auction system  (Read 1338 times)

Offline Zeggy

  • Global Moderator
  • Level 35
  • *****
  • Posts: 1,187
  • Reputation: +13/-4
    • View Profile
Auction system
« on: December 08, 2007, 01:25:14 PM »
I'm helping somebody code an auction system, and I've run into some problems in terms of how the timing works.

The auctions are started by the website users, and they can set their own time limits. The problem is when do I decide that the auction is finished and start processing?

I could run a cron every minute or so but I don't think that would be so efficient.

Are there any other solutions to this?

I was thinking I could just use a timestamp, and check against that every time somebody refreshes a page. The load is then spread out among the users and over time, not all in one go each time the cron is run, but still... It doesn't sound very efficient either :P

Offline hexsane

  • Level 4
  • *
  • Posts: 12
  • Reputation: +0/-0
    • View Profile
Re: Auction system
« Reply #1 on: December 08, 2007, 01:35:03 PM »
I was thinking I could just use a timestamp, and check against that every time somebody refreshes a page. The load is then spread out among the users and over time, not all in one go each time the cron is run, but still... It doesn't sound very efficient either :P

Actually that is a good way to do it. It allows you to run any processing scripts that haven't already been run when the page is refreshed. Having a timestamp you'll know if they have ended or not. Have a cron for checking the unrefreshed auctions running to do processing otherwise. Without having an actual service/daemon running that handles this for you there isn't much of an option. Your cron script (sql query) could limit what you are checking to only the next few minutes which should keep the overhead down.

Offline Chris

  • Game Owner
  • Level 35
  • *
  • Posts: 2,217
  • Reputation: +28/-1
    • View Profile
Re: Auction system
« Reply #2 on: December 11, 2007, 03:07:40 PM »
I was thinking I could just use a timestamp, and check against that every time somebody refreshes a page. The load is then spread out among the users and over time, not all in one go each time the cron is run, but still... It doesn't sound very efficient either :P
I uses something like that in my game. It's OK solution (and very good CPU wise) but quite troublesome. It will take a while until you code it properly. And there will be problems with more users (but it can be solved).
First, use a filed in the table to tell when the nearest aution will end and run the script only if that time is reached. And set a new "virtual cron time check" value at the end of the script. Sort of :)

Offline Dasein Fiasco

  • Level 15
  • *
  • Posts: 132
  • Reputation: +2/-0
    • View Profile
    • Travis Dunn
Re: Auction system
« Reply #3 on: December 18, 2007, 07:50:15 PM »
Regular cron script++. I'd be surprised if it turns out to be a performance bottleneck. Too many concurrency issues in your other options, which is not something you want to deal with when people's money is involved.
Personal Site: www.travisdunn.com
There is neither speech nor language but their voice is heard among them

Offline JGadrow

  • Level 35
  • **
  • Posts: 1,133
  • Reputation: +23/-2
    • View Profile
Re: Auction system
« Reply #4 on: January 18, 2008, 09:55:06 AM »
As noted above, your best option would be to code some sort of 'service' that would perform this task for you. Storing the timestamp in a database table is a good idea. You can just have your service continually scan the database table, performing the operation upon any scripts it finds that should be processed.
Idiocy - Never underestimate the power of stupid people in large groups.


Offline codestryke

  • Administrator
  • Level 33
  • *****
  • Posts: 589
  • Reputation: +22/-0
    • View Profile
    • eXtremeCast Games
Re: Auction system
« Reply #5 on: January 18, 2008, 12:30:13 PM »
First the front end, your queries and such, code those so that once the auction ends they do not display as available.

Then use a cron that runs every 5 mins and resolves any auctions that have cleared since the last 5 mins.

This was the solution I found best to work with LAMP. Like the others said if you want real-time then you would have to create a deamon / service which is usually run on a separate box and does nothing but resolves auctions as soon as they happen.

With the cron processing I was able to process ~3k auctions every 5 mins. Once I got over 3k the cron was taking longer to execute then 5 mins and so I had to adjust some items but I would say 3k is not a normal load to be processing every 5 mins so that will work for you for quite  a while.
Creating online addictions, one game at a time:

 


SimplePortal 2.3.3 © 2008-2010, SimplePortal