关于给用户发送邮件的一些问题
现在要给全部用户或者指定用户发送邮件,“发送”操作是由我们后台人员触发的。
发送操作提交后,我们就要给用户发送了,在发送过程中可能会存在一个问题,就是发送了一段时间后,程序因某些原因死掉了,这样就导致一些用户没有收到邮件,所以我的想法是发送前先把数据库里的用户全写入到一个文件中,发送时从文件中取用户,然后再弄个用户发送日志以记录哪些用户发送了,这样出问题后,可以从出问题的“那个地方”接着执行发送.....
不知道我的想法行不行,另外我担心“把数据库中的用户写入到文件中”这个过程所花费的时间会很长,从而导致性能上会存在隐患。谢谢大家讨论我的想法,给些意见或指点!
回复内容:
现在要给全部用户或者指定用户发送邮件,“发送”操作是由我们后台人员触发的。
发送操作提交后,我们就要给用户发送了,在发送过程中可能会存在一个问题,就是发送了一段时间后,程序因某些原因死掉了,这样就导致一些用户没有收到邮件,所以我的想法是发送前先把数据库里的用户全写入到一个文件中,发送时从文件中取用户,然后再弄个用户发送日志以记录哪些用户发送了,这样出问题后,可以从出问题的“那个地方”接着执行发送.....
不知道我的想法行不行,另外我担心“把数据库中的用户写入到文件中”这个过程所花费的时间会很长,从而导致性能上会存在隐患。谢谢大家讨论我的想法,给些意见或指点!
和@舞林 同学的想法有点相似:
- 把待发的邮件,存储到列表(Lists)中,通过
lpush
插入到Redis
消息队列中 - 负责发送邮件的代码中通过BRPOP依次消息队列中的内容并进行处理,如果没有新邮件则会阻塞等待直到有新的消息
这样的话不管程序死掉或者什么原因都不会千万消息丢失,同时也可以不用另外加一个定时任务
相比于写文件或者是其它的方法,Redis
是目前最合适的
Redis是一个开源、支持网络、基于内存、键值对存储数据库
参考:http://zh.wikipedia.org/zh/Redis
我的做法是邮件队列,放redis,crontab每分钟发送,脚本起来的时候发现上个脚本还在跑就退出,为了避免异常,脚本最多执行110秒。做好失败的监控,没啥问题。
还有什么呢,继续吧...

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



When MySQL modifys table structure, metadata locks are usually used, which may cause the table to be locked. To reduce the impact of locks, the following measures can be taken: 1. Keep tables available with online DDL; 2. Perform complex modifications in batches; 3. Operate during small or off-peak periods; 4. Use PT-OSC tools to achieve finer control.

Data Integration Simplification: AmazonRDSMySQL and Redshift's zero ETL integration Efficient data integration is at the heart of a data-driven organization. Traditional ETL (extract, convert, load) processes are complex and time-consuming, especially when integrating databases (such as AmazonRDSMySQL) with data warehouses (such as Redshift). However, AWS provides zero ETL integration solutions that have completely changed this situation, providing a simplified, near-real-time solution for data migration from RDSMySQL to Redshift. This article will dive into RDSMySQL zero ETL integration with Redshift, explaining how it works and the advantages it brings to data engineers and developers.

1. Use the correct index to speed up data retrieval by reducing the amount of data scanned select*frommployeeswherelast_name='smith'; if you look up a column of a table multiple times, create an index for that column. If you or your app needs data from multiple columns according to the criteria, create a composite index 2. Avoid select * only those required columns, if you select all unwanted columns, this will only consume more server memory and cause the server to slow down at high load or frequency times For example, your table contains columns such as created_at and updated_at and timestamps, and then avoid selecting * because they do not require inefficient query se

The MySQL primary key cannot be empty because the primary key is a key attribute that uniquely identifies each row in the database. If the primary key can be empty, the record cannot be uniquely identifies, which will lead to data confusion. When using self-incremental integer columns or UUIDs as primary keys, you should consider factors such as efficiency and space occupancy and choose an appropriate solution.

MySQL cannot run directly on Android, but it can be implemented indirectly by using the following methods: using the lightweight database SQLite, which is built on the Android system, does not require a separate server, and has a small resource usage, which is very suitable for mobile device applications. Remotely connect to the MySQL server and connect to the MySQL database on the remote server through the network for data reading and writing, but there are disadvantages such as strong network dependencies, security issues and server costs.

MySQL can return JSON data. The JSON_EXTRACT function extracts field values. For complex queries, you can consider using the WHERE clause to filter JSON data, but pay attention to its performance impact. MySQL's support for JSON is constantly increasing, and it is recommended to pay attention to the latest version and features.

MySQL can handle multiple concurrent connections and use multi-threading/multi-processing to assign independent execution environments to each client request to ensure that they are not disturbed. However, the number of concurrent connections is affected by system resources, MySQL configuration, query performance, storage engine and network environment. Optimization requires consideration of many factors such as code level (writing efficient SQL), configuration level (adjusting max_connections), hardware level (improving server configuration).

MySQL has a free community version and a paid enterprise version. The community version can be used and modified for free, but the support is limited and is suitable for applications with low stability requirements and strong technical capabilities. The Enterprise Edition provides comprehensive commercial support for applications that require a stable, reliable, high-performance database and willing to pay for support. Factors considered when choosing a version include application criticality, budgeting, and technical skills. There is no perfect option, only the most suitable option, and you need to choose carefully according to the specific situation.
