我有一个Ruby应用程序,每分钟需要大约10000个请求。 其中一些请求执行写入数据库表。到数据库的最大连接数是200.写入缓存vs写入数据库 - 性能基准?
我想知道什么是更高效。在缓存中写入数组并将数据保存在后台中,或将每个请求直接保存到数据库中? 如果我将数据写入缓存中的数组,是否有任何竞争条件或性能问题? 有没有更好的方法来优化性能并避免数据库瓶颈?
示例代码
#...
def self.add_data_message_to_queue(event_id, chat_item)
bucket_name = 'BUCKET_GET_CHAT_' + event_id.to_s
chat_queue = Rails.cache.fetch(bucket_name)
if chat_queue.blank?
chat_queue = []
end
chat_queue.push(chat_item)
Rails.cache.write(bucket_name, chat_queue, expires_in:Integer(30).days)
end
- 服务器:独角兽(高并发)
在此先感谢