mysql队列写入_MySQL插入语句队列

bd96500e110b49cbb3cd949968f18be7.png

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?

解决方案

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 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:

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

Use MyISAM with concurrent inserts

Rotate tables daily and use UNION to query

Use delayed inserts with MySQL or a job processing agent like Gearman (although MySQL has a limit on the number of these it will queue before silently dropping them!)

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值