dsa122870 2009-08-25 20:50
浏览 44
已采纳

订阅 - 如何处理大量内容和订阅金额?

I am sending notification to my users depending on what kind of subscription each user has.

For example:

  • User A subscribed to all news articles
  • User B subscribed to all comments
  • User C subscribed to everything that is new on the site

I have a script running every 5 minutes (unless the script is still running) who does the following:

  1. Get new "content" (comments, news articles, etc) posted since the last run
  2. For each result, fetch each users who subscribed to "content"
  3. For each users, sends a notification

What I'm concerned with is, if I have a 1,000 new "content" and my users are subscribe to 50% of it, my script will take forever to finish or will crash my server.

What I come up with is to select only 100 new "content" per run and notify the users. I still have the problem of the amount of users that can be subscribed to it.

Than I thought, I could limit the amount of users I select also to 100, than iterate until I reach all users.

Is this the right approach? Is there an easier way to do this? How does large websites handle their users notifications?

  • 写回答

2条回答 默认 最新

  • doubo1883 2009-08-25 22:07
    关注

    Being able to process (and send mails to) batches of users could be handy in terms of architecture as if the work became too much for a single process/server you could have multiple "works" all working on their own batches.

    That said I'm not sure about your concerns of the script taking a long time to run or crashing the server. I think that's an issue for you to work through in the code. Profiling the code and the db queries you're doing are a must.

    If you do go the route of batches you'll end up having to try to keep track of what notifications you've sent out to which users. I'd suggest strongly that you'd don't keep a table with a row for each user-content pair. If you simply store the time of the last event (article or comment publish time) that was sent to the user it will be easy to work out what you still need to send them and you won't end up with a huge table.

    To re-iterate I'd suggest profiling the code and queries as a research task and work out the most effective method through that route.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用