duanjiu4498 2012-12-21 11:53
浏览 32
已采纳

通知系统(电子邮件,社交媒体)

I'm currently writing a small internal social media platform for the company I'm working with, nothing big, approx. 40,000+ users. It is basically something like Facebook or Google+ but with way less features.

This platform has an email notification system (beside the Ajax notifications for online users) as well.

Now here's my issue - it's simply not scaling.

I have a mySQL table holding all the email notifications to be sent out. So as soon as somebody writes a story in a group the system automatically inserts a line into that table and an email_send function (cronjob) will send out those mails to the users (the users can choose between instant, daily or weekly notification mails)

So far, so good - if the groups have a low number of members.

But now image a group with 5k+ members - As soon as the user posts a story into that group it triggers 5,000 SQL inserts to the notification table.

How would you solve this? I thought of a background worker on the server what scans for new stories/comments/stuff and triggers the email_send function in the background. Would this scale better? Or is there just a standard way for this and I'm just thinking in the wrong direction?

Any point in the right direction would be pretty much appreciated, Thank you and merry xmas :)

// Markus.

  • 写回答

2条回答 默认 最新

  • dptiq46022 2012-12-21 11:58
    关注

    You should not slow down your normal web request/response flow by sending emails - simply dump the data in a queue and let a background job pick up that work - it sounds like you are doing this already with your cron right?

    So is it the insert that is the cause of the slowness? Then just normalize your data and simply insert a groupID in your email queue table. That groupID is associated with a group that contains X users and their email addresses. So then you will be inserting 1 record instead of 5000. So very quickly perhaps something like this...

    notificationTable
    rowID | emailID | groupID | status
    
    groupTable
    groupID | groupName 
    
    userTable
    userID | userName | emailAddress | groupID
    

    If you want to take it even further then you could introduce a messaging system so that you can fire off simple (and fast) messages and have one or more listeners (on one or more separate servers) waiting for messages on one or more channels.

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

报告相同问题?

悬赏问题

  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据