Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Simple Ad-Server

I'm in the middle of a project where we have created the backend for handling ad campaigns in Grails and I am trying to figure out the best way to create the ad-server part. I.e. the part that is going to serve the actual ads to the end users (browsers).

In my last three projects I have been using Grails, which I have come to enjoy very much for it's rapid development and good support from the Java community through Spring and Hibernate. However, Grails still has some performance issues, and I'm not sure it is the right choice for this task. I have been looking at other alternatives, but can't decide which way to go. The server needs to be able to handle around a couple of thousand requests per second, plus needs to be robust. The DB structure is as follows (simplified):

Ad ==> site, position, percent of view (percent of time the ad is shown)

So basically, the Ad Server needs to get the necessary rows from the DB for the specific site and position and choose which Ad to display (depending on percentage).

Bellow are the different choices I am considering (all of which should have multiple instances and use a load balancer).

  • Grails together with Redis and MongoDB - I haven't found any reports on performance with this trio. In my previous projects we have found that Grails has lots of performance issues, a lot of them we have handled in different ways, but for an Ad Server, I'm not sure it will do.
  • Node.js together with a key-value store - Node.js is supposedly very fast, but it would be a bit risky to implement it at this stage since it is not yet stabilized.
  • Ruby on Rails together with a key-value store - Haven't done any Ruby on Rails development yet, but from what I can gather from googling around, Ruby on Rails has a lot better performance than Grails.
  • PHP with a key-value store - Haven't done any PHP programming either, but there are a lot of big sites using PHP that have good performance, so it should be considered a good alternative.

Any suggestion or recommendations are warmly welcomed.

like image 321
Mr.B Avatar asked May 16 '11 17:05

Mr.B


2 Answers

Don't serve any images from the application use a CDN for that. As long as the only thing your application has to do is determine what add to display and return the link to the CDN stored ad then you should be fine to serve your thousands of requests per second. Also don't look to serve everything from one server. Load balancing is your friend in an application like this and it is unreasonable to blame all performance issues on the framework of choice.

like image 151
Devin M Avatar answered Oct 02 '22 14:10

Devin M


100.000 rows is small enough to store in memory. With node.js I would try out keeping the data in an in-process DB. Assuming the data set doesn't grow too large, and updates to the DB are infrequent, a very simple node server should yield good performance.

ad.db :

{ key:'site:position', value: [{id:'1424234', percent:50}, { id:'8394847', percent:50}] }

url :

http:://adserver.com/?add=site:position

adServer.js :

var http = require('http');
var url = require('url');
var db = require('dirty')('ad.db');

var server = http.createServer(function (req, res) {
  var query = url.parse(req.url, true).query.add;
  var adds = db.get(query);
  var random = Math.floor( Math.random() * 100 );
  var id = '';
  for( var i = 0, len = adds.length; i < len; i++ ) {
    if( random < adds[i].percent ) {
      id = adds[i].id;
      break;
    } else {
      random += adds[i].percent;
    }
  }
  res.writeHead(200, {'Content-Type': 'text/html'});
  res.end('<img src="http://cdn.com/' + id + '.jpg" alt='' />');
});
db.on('load', function() {
  server.listen(80);
});
like image 41
generalhenry Avatar answered Oct 02 '22 16:10

generalhenry