简单的广告服务器

发布于 2024-11-07 17:54:10 字数 1012 浏览 0 评论 0原文

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

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

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

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

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

  • GrailsRedis 一起使用 MongoDB - 我还没有找到任何报告 关于这三人组的表演。在我的 之前的项目我们发现 Grails 有很多性能 问题,其中很多我们已经处理过 以不同的方式,但对于广告 服务器,我不确定是否可以。
  • Node.js 与键值一起 store - Node.js 据说非常 速度很快,但是风险有点大 在此阶段实施它,因为 尚未稳定下来。
  • Ruby on Rails 以及 键值存储 - 还没有做过任何事情 Ruby on Rails 尚未开发,但是 据我所知 谷歌搜索了一下,Ruby on Rails 有 性能比 圣杯。
  • PHP 具有键值存储 - 还没有 也做过任何 PHP 编程,但是 有很多大网站使用 PHP 具有良好的性能,所以它 应该被认为是一个好的 选择。

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

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

独享拥抱 2024-11-14 17:54:10

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

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.

小矜持 2024-11-14 17:54:10

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

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);
});

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);
});
终止放荡 2024-11-14 17:54:10

我发现这些比较 Java 和 Node.js 的性能:

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

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

他们建议 Java 的速度是其两倍,但请自行尝试。

您将拥有多少种站点、位置、百分比等组合?未来你会添加多少个新维度?可能值得在启动时加载所有这些,以避免不断地访问数据库。您可以使用它们的组合来快速构建一个密钥,您可以在内存中查找广告的地址。这在 Grails 中应该足够快了。

对于每秒数千个请求,您可能会看到一个集群场,前面有一个负载均衡器。取决于构建页面内容的逻辑的复杂性。

一旦确定了浏览器用于加载广告的 URL,我喜欢 CDN 的想法,但这可能会很昂贵!

如果是我,我会坚持使用一种技术(Grails)并在遇到问题时解决它们。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文