【问题标题】:How to make Mahout recommender work faster?如何让 Mahout 推荐器工作得更快?
【发布时间】:2012-10-12 17:00:16
【问题描述】:

嗨,SO 的 Mahout 社区!

我有几个关于加快推荐计算的问题。在我的服务器上,我安装了没有 Hadoop 的 Mahout。 jRuby 也用于推荐脚本。在数据库中,我有 3k 个用户和 100k 个项目(连接表中有 270k 个项目)。因此,当用户请求推荐时,简单的脚本就会开始工作:

首先它使用PGPoolingDataSource 建立数据库连接,如下所示:

  connection = org.postgresql.ds.PGPoolingDataSource.new()
  connection.setDataSourceName("db_name");
  connection.setServerName("localhost")
  connection.setPortNumber(5432)
  connection.setDatabaseName("db_name")
  connection.setUser("mahout")
  connection.setPassword("password")
  connection.setMaxConnections(100)
  connection

我收到此警告:

WARNING: You are not using ConnectionPoolDataSource. Make sure your DataSource pools connections to the database itself, or database performance will be severely reduced.

有什么办法解决这个问题吗?

之后我创建推荐:

model = PostgreSQLJDBCDataModel.new(
    connection,
    'stars',
    'user_id',
    'repo_id',
    'preference',
    'created_at'
  )

  similarity = TanimotoCoefficientSimilarity.new(model)
  neighborhood = NearestNUserNeighborhood.new(5, similarity, model)
  recommender = GenericBooleanPrefUserBasedRecommender.new(model, neighborhood, similarity)
  recommendations = recommender.recommend user_id, 30

目前,为一位用户生成推荐大约需要 5-10 秒。问题是如何更快地提出建议(200 毫秒就好了)?

【问题讨论】:

    标签: apache hadoop mahout


    【解决方案1】:

    如果您知道自己正在使用池数据源,则可以忽略该警告。这意味着该实现没有实现池化实现的常用接口ConnectionPoolDataSource

    如果尝试直接从数据库运行,您将永远无法快速运行。有太多的数据访问。将JDBCDataModel 包裹在ReloadFromJDBCDataModel 中,它将被缓存在内存中,这应该可以快100 倍。

    【讨论】:

    • 肖恩,我希望得到你的回答,非常感谢 - ReloadFromJDBCDataModel 正是我所需要的。如果没有重新加载,一个用户需要 8 秒,而重新加载我在 18 秒内处理了 119 个用户。速度提高了 53 倍!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-12-27
    • 1970-01-01
    • 2014-04-18
    • 1970-01-01
    • 2014-06-06
    • 1970-01-01
    相关资源
    最近更新 更多