将大文件上传到 BLOB
我正在将大文件(~200mb)直接保存到数据库中。
我对此有疑问。
由于文件保存到数据库时舞台上大量使用可用 RAM(大约 3GB RAM 和 3GB 交换区)导致:
@job.pdf = params[:job][:pdf].read
完成此操作后,仍然有一些 RAM 和交换区在使用中。
有什么办法可以优化吗?
Rails 3.0.3上的ps项目,使用mysql,在mogrel上运行。
I'm working with saving big files(~200mb) directly into db.
I have issue with that.
Caused by increased huge use of free RAM(about 3gb of ram and 3gb of swap) on stage when file saves to db:
@job.pdf = params[:job][:pdf].read
After this is completed there is still some RAM and swap in use.
Is there some way to optimize that?
p.s. project on rails 3.0.3, uses mysql, running on mogrel.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在 MySQL 中,为了能够保存或读取大小超过 1MB 的 BLOB 字段,必须将服务器端参数 max_allowed_packet 增加到大于默认值。实际上,此参数的大小不能超过 16-32MB。这种增加的代价是每个新的数据库客户端都将消耗至少同样多的内存,并且一般来说,服务器性能将受到极大影响。
换句话说,MySQL 并不真正支持处理大于 1MB(如果您不能或不想摆弄服务器配置)到 16MB 左右(即使您确实想这样做)的 BLOB 字段。
这可能是一个哲学问题——在数据库中保留大块是好主意还是不好主意?我认为对于许多任务(但不是所有任务)来说这是个好主意,而且因为 MySQL 太糟糕了(以及许多其他原因),我只是避免使用它作为我的 SQL 服务器解决方案。
相反,我使用 PostgreSQL,它完美支持 BLOB(实际上是 BYTEA),达到 4GB 的限制,而无需在客户端或服务器上进行任何调整。除此之外,它实际上会使用 LZ 算法透明地压缩它们 - 比 gzip 稍差,但仍然比根本不压缩要好得多。
In MySQL, to be able to save or read BLOB fields with size more than 1MB, you have to increase server side parameter max_allowed_packet to be larger than default. In practice, you can't go much farther than 16-32MB for this parameter. Price for this increase is that every new db client will consume at least as much memory, and in general, server performance will greatly suffer.
In other words, MySQL does not really support handling BLOB fields larger than 1MB (if you can't or don't want to fiddle with server configuration) to around 16MB (even if you do want to do that).
This can be philosophical question - is it good idea or not to keep big blobs in database? I think for many tasks (but not for all) is it great idea, and because MySQL is so bad it this (and for host of other reasons), I simply avoid using it as my SQL server solution.
Instead, I use PostgreSQL, which perfectly supports BLOBs (actually, BYTEA) to advertized limit of 4GB without any tweaks on client or server. In addition to that, it will actually transparently compress them with LZ algorithm - slightly worse than gzip, but still much better than no compression at all.