5

我正在进行一个项目,我们在 Grails 中创建了用于处理广告活动的后端,我正在尝试找出创建广告服务器部分的最佳方法。即将向最终用户(浏览器)提供实际广告的部分。

在我最近的三个项目中,我一直在使用 Grails,我非常喜欢它,因为它的快速开发和 Java 社区通过 Spring 和 Hibernate 提供的良好支持。但是,Grails 仍然存在一些性能问题,我不确定它是否是完成这项任务的正确选择。我一直在寻找其他选择,但无法决定走哪条路。服务器需要能够每秒处理大约几千个请求,并且需要强大。DB结构如下(简化):

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

所以基本上,广告服务器需要从数据库中获取特定站点和位置的必要行,并选择要显示的广告(取决于百分比)。

下面是我正在考虑的不同选择(所有这些都应该有多个实例并使用负载均衡器)。

  • Grails连同RedisMongoDB——我还没有找到任何关于这三者的性能报告。在我之前的项目中,我们发现 Grails 存在很多性能问题,其中很多问题我们以不同的方式处理,但对于广告服务器,我不确定它是否能解决问题。
  • Node.js和键值存储 - Node.js 据说非常快,但在这个阶段实施它会有点冒险,因为它还没有稳定。
  • Ruby on Rails 和键值存储 - 还没有做过任何 Ruby on Rails 开发,但从我在谷歌搜索中收集到的信息来看,Ruby on Rails 的性能比 Grails 好得多。
  • 带有键值存储的PHP - 也没有做过任何 PHP 编程,但是有很多使用 PHP 的大型站点具有良好的性能,因此应该将其视为一个不错的选择。

任何建议或建议都受到热烈欢迎。

4

3 回答 3

3

不要使用 CDN 提供来自应用程序的任何图像。只要您的应用程序唯一要做的就是确定要显示的内容并将链接返回到 CDN 存储的广告,那么您应该可以每秒处理数千个请求。也不要指望从一台服务器上提供所有服务。在这样的应用程序中,负载平衡是您的朋友,将所有性能问题归咎于所选框架是不合理的。

于 2011-05-16T18:18:54.997 回答
2

100.000 行足够小,可以存储在内存中。使用 node.js,我会尝试将数据保存在进程内数据库中。假设数据集不会变得太大,并且对数据库的更新不频繁,那么一个非常简单的节点服务器应该会产生良好的性能。

广告数据库:

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

网址:

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);
});
于 2011-05-17T20:33:44.670 回答
1

I found these comparing Java to node.js, concerning performance:

http://www.olympum.com/java/quick-benchmark-java-nodejs/

http://www.olympum.com/java/java-aio-vs-nodejs/

They suggest Java is twice as fast, but do your own trials.

How many combinations of site, position, percent, etc. will you have? How many new dimensions will you add in the future? Probably worth loading all of them at startup to avoid constantly hitting the database. You could use the combination of them to build a key fast, which you lookup the address of the ad in memory. This should be fast enough in Grails.

For thousands of requests a second, you are probably looking at a clustered farm, with a load balancer up front. Depends on the complexity of the logic that builds the content of the page.

Once you have determined the URL which the browser should use to load the ad, I like the idea of a CDN, but that could get expensive!

If it were me, I would stick to the one technology (Grails) and iron out the problems as I face them.

于 2011-05-16T19:44:58.983 回答