MySQL插入语句队列 [英] MySQL Insert Statement Queue

查看:457
本文介绍了MySQL插入语句队列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在构建一个ajax应用程序,其中将用户输入提交到处理PHP脚本。我们目前正在将每个请求写入日志文件以进行跟踪。我想将此跟踪移动到数据库表,但我不想在请求后运行insert语句。我想做的是设置需要在MySQL数据库上处理的事务(插入和更新)的队列。然后我将设置一个cron作业或进程来检查和处理队列中的事务。有没有什么我们可以建立的,或者我们只需要写简单的文本日志文件并处理它们?

We are building an ajax application in which a users input is submitted for processing to a php script. We are currently writing every request to a log file for tracking. I would like to move this tracking into a database table but I do not want to run a insert statement after request. What I would like to do is set up a 'queue' of transactions (inserts and updates) that need to be processed on the MySQL database. I would then set up a cron job or process to check and process the transactions in the queue. Is there something out there that we could build upon or do we have to just write to plain ol' text log files and process them?

推荐答案

您希望 Gearman - 它会将请求排入队列,并在数据库准备好时将其插入

You want Gearman - it'll queue the requests and insert them as and when the database is ready for them, so you don't overload your DB server.


Gearman提供了一个通用的应用程序
框架来将工作转移到其他
机器或过程更好的
适合做这项工作。它允许
并行工作,加载
余额处理,以及在语言之间调用
函数。它可以是
用于各种应用程序,
从高可用性网站到
传输数据库复制
事件。换句话说,
处理通信的分布是
神经系统。几个强大的
点关于Gearman:

Gearman provides a generic application framework to farm out work to other machines or processes that are better suited to do the work. It allows you to do work in parallel, to load balance processing, and to call functions between languages. It can be used in a variety of applications, from high-availability web sites to the transport of database replication events. In other words, it is the nervous system for how distributed processing communicates. A few strong points about Gearman:

最近有一篇关于使用数据库记录=http://brian.moonspot.net/logging-with-mysql =nofollow noreferrer>这里,其中(总结)说:

There's a recent (and quality) post about using databases for logging here, which (summarised) says:


  • 使用MyISAM并发插入

  • 每天轮换表格并使用UNION查询

  • 一个像Gearman这样的工作处理代理(虽然MySQL对这些代理的数量有限制,但是会默认丢弃它们。)

HighScalability 撰写Gearman

HighScalability write up on Gearman.

如果你真的想要避免这种情况,你可以将原始SQL语句写入一个文件,并用这个cronjob处理:

If you really want to avoid this, you could write the raw SQL statements to a file and process them with this cronjob:

mysql loggingDB logTable < fullLog.sql && > fullLog.sql

这篇关于MySQL插入语句队列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆