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).
Any suggestion or recommendations are warmly welcomed.
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.
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);
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With