- r - 以节省内存的方式增长 data.frame
- ruby-on-rails - ruby/ruby on rails 内存泄漏检测
- android - 无法解析导入android.support.v7.app
- UNIX 域套接字与共享内存(映射文件)
我有以下类(class)女巫在论坛中存储一条消息
using System;
using System.Collections.Generic;
public partial class ForumMessage
{
public ForumMessage()
{
this.Votes = new HashSet<ForumMessageVote>();
OnCreated();
}
partial void OnCreated();
public long id { get; set; }
public int forumId { get; set; }
public Nullable<long> parentId { get; set; }
public int memberId { get; set; }
public int lastModifiedMemberId { get; set; }
public Nullable<long> lastReplyId { get; set; }
public string title { get; set; }
public string body { get; set; }
public string imagePath { get; set; }
public Nullable<bool> isSticky { get; set; }
public Nullable<bool> allowPosts { get; set; }
public Nullable<bool> allowImages { get; set; }
public Nullable<bool> allowYoutube { get; set; }
public Nullable<bool> allowBbCode { get; set; }
public Nullable<long> totalMessages { get; set; }
public Nullable<long> totalViews { get; set; }
public Nullable<long> totalDailyViews { get; set; }
public Nullable<int> totalVotes { get; set; }
public Nullable<long> totalScore { get; set; }
public bool published { get; set; }
public Nullable<System.DateTime> publishedDate { get; set; }
public Nullable<System.DateTime> lastModifiedDate { get; set; }
public Nullable<bool> isTemporary { get; set; }
public Nullable<System.DateTime> lastReplyDate { get; set; }
public Nullable<int> lastReplyMemberId { get; set; }
public Nullable<long> sortByLastReplyId { get; set; }
public Nullable<bool> containsImage { get; set; }
public Nullable<bool> containsVideo { get; set; }
public Nullable<bool> @private { get; set; }
public virtual Forum Forum { get; set; }
public virtual ICollection<ForumMessageVote> Votes { get; set; }
public virtual Member Member { get; set; }
}
目前,我正在使用 Booksleeve 缓存这些对象,方法是使用以下代码(简化版)将它们与 Json 序列化存储在字符串键中(当然在 Redis 中):
using (var conn = conn.CreateTransaction())
{
return conn.Store<ForumMessage>(db, message.id, message);
}
在我的论坛应用程序 View 中,我使用了上述大部分字段,因为我显示了属于论坛主题的上述消息列表。
为了获取 ForumMessage 类的列表,我使用了 mget 命令。
当用户发布新消息或为消息投票时,我需要更新上面的一些字段。当我更新时,我通过 redis get 获取消息,更新所需的字段(主要是一个或两个字段),然后我通过 conn.store booksleeve 方法存储更新.
目前论坛在高峰时段收到约12条消息/分钟和20票/分钟(总票数不是每条消息)
我想知道是否有更好的解决方案是将消息存储在 Redis 哈希中,因为那样更新会更快。但是为了使用哈希,在 redis 中进行初始存储的代码将更加复杂(缓慢),并且该代码将在 web 服务器而不是 redis 服务器上运行。
您认为通过使用哈希或我现在使用的解决方案重新实现消息存储/检索过程是否值得,例如当消息插入速率以 30 条消息/分钟的速度增加时能够很好地扩展?
本质上,您能否就 stackoverflow 如何处理这种情况提供一些指南?
最佳答案
散列很适合这里,主要是因为该数据结构针对共享一个整体身份(包括过期等)的多个命名值。如果您当前使用的是 MGET
,则性能不会有巨大差异。 - 对于哈希,您只需我们 HMGET
, HGETALL
, 和 HMSET
.
我看不出这会使其变得更复杂:您只需将预期的更改填充到 Dictionary<string,byte[]>
中即可。并使用 .Hashes.Set(...)
.一次而不是打电话 .Strings.Set
多次。同样,使用 .Strings.Get(...)
的 varadic 形式与调用 .Hashes.GetAll(...)
没有太大区别或 .Hashes.Get(...)
的可变形式.
我也不接受这段代码会变慢——事实上,它基本上是相同的。事实上,在实现层面,一次调用 .Hashes.Set
在 Task
方面涉及更少的开销等等,因为它是一个单一的可等待/等待操作。
Currently the forum at peak hours receives about 12 messages / minute and 20 votes / minute(total votes not per message)
吞吐量应该不会成为问题。 Redis 在每秒 数千 条消息中愉快地工作。
Do you think it worth to reimplement the message store/retrieve procedure by using hashes or the solution than I'm using right now will be able to scale fine when for example the rate of message inserts increase with 30 messages/minute?
该消息速率应该没有问题。如果您发现问题,请详细说明。然而,最简单和最合适的下一步是模拟一些更高的负载 - 看看有什么效果。
In essence can you provide some guidelines on how stackoverflow handles this situations?
我们通常使用 SQL 数据库作为我们的主要数据存储(尽管有些东西只保存在 redis 中)。我们广泛使用 Redis 将已处理的项目存储为缓存,但由于它们不受更改的影响,因此我们不会逐个字段地存储它们:相反,我们针对 DTO 类型使用 protobuf-net 并存储数据 block (使用字符串类型,即 GET
/SET
)。此外,如果大小超过阈值(只要它不进入集合/排序集合),我们会进行快速“gzip”测试,看看如果我们压缩它是否会变小(不是所有的东西)确实):如果是,我们存储它 - 所以我们有绝对最小的带宽和存储开销,并且在存储/获取时处理速度非常快。为清楚起见,我们不在集合/排序集合中压缩的原因是 gzip 不能保证每次输出完全相同,这会扰乱哈希。
关于c# - 使用 Redis 和 Booksleeve 存储论坛消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22467649/
我目前正在使用 php 和 sql 创建一个论坛。我的问题是如何将主题按正确的顺序排列,假设每页总共有 200 和 15 个主题,而我在第 10 页上。 我无法选择每个 ID,因为如果有人将时间戳发布
Closed. This question does not meet Stack Overflow guidelines。它当前不接受答案。 想要改善这个问题吗?更新问题,以便将其作为on-topi
基本上,我正在为 Intranet 编写一个小型论坛脚本。 我有 3 个用于论坛的 mysql (MySQLi) 表: forum_answer - 保存回复forum_quest - 持有第一个帖子
我正在尝试实现 django-registration-redux 并使用了由 Andres 编写的模板,网址为 https://github.com/macdhuibh/django-registr
我正在开发一个讨论论坛网站。当您打开论坛时,网络服务会获取所有活跃的帖子。 标题、评论数、近期事件(最新评论的日期)、发布者、状态。 除最近的事件外,我能够获取上述所有数据。 SELECT `po
我有一个使用 phpBB 的论坛。现在我想从源代码做这样的事情: 登录(“用户”,“密码”) 如何在 phpBB 中执行此操作? 最佳答案 首先你需要为 phpBB 引导: define('IN_PH
我想知道检测人们在我的论坛上提交帖子时使用的字母表的最佳方法(对博客也很有用)。事情是最近我收到了很多西里尔字母、希腊字母和日语的垃圾邮件,所以由于我的论坛是为讲法语和英语的人准备的,所以我想防止垃圾
很难说出这里要问什么。这个问题模棱两可、含糊不清、不完整、过于宽泛或夸夸其谈,无法以目前的形式得到合理的回答。如需帮助澄清此问题以便重新打开,visit the help center . 关闭 1
所以我几年前创建了这个 vBulletin 论坛,几个月前它开始时不时地通过电子邮件向我发送错误消息。由于我在创建网站时注册为论坛管理员,现在当出现错误时它会向我发送电子邮件。网站所有者和我聚在一起,
我很难在不同的 php 论坛之间进行选择。我正在寻找一个轻量级、安全且易于定制的论坛。 谷歌搜索给我提供了几十个由个人制作的“简单的 php 论坛”,但我正在寻找一个基于社区的论坛。因为,你知道,帮助
关闭。这个问题是off-topic .它目前不接受答案。 想改进这个问题吗? Update the question所以它是on-topic用于堆栈溢出。 关闭 12 年前。 Improve thi
我一直在寻找新的论坛软件(线程)或公告板(平面/分区)。我想知道是否有基于大型 PHP 框架之一的实现(CodeIgniter、Kohana、Yii、CakePHP、ZF、Seagull、Fusebo
关闭。这个问题是off-topic .它目前不接受答案。 想改进这个问题吗? Update the question所以它是on-topic用于堆栈溢出。 关闭 10 年前。 Improve thi
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 我们不允许提问寻求书籍、工具、软件库等的推荐。您可以编辑问题,以便用事实和引用来回答。 关闭 7 年前。
我知道这个问题已经在这里问过几次了,但没有一个答案让我满意。这是因为几乎所有这些都涉及与数据库相关的巨大读/写过程,我想不惜一切代价避免。 关于未读的讨论/主题/帖子,有很多事情要考虑。不知道MyBB
我被指派在我们已经使用了一段时间的内部 CMS 中添加一个论坛。该系统有自己的登录/用户系统和已建立的用户数据库。理想情况下,我会寻找最简单的论坛软件来转换为与我们的系统一起使用,但如果有必要,可以重
已结束。此问题正在寻求书籍、工具、软件库等的推荐。它不满足Stack Overflow guidelines 。目前不接受答案。 我们不允许提出寻求书籍、工具、软件库等推荐的问题。您可以编辑问题,以便
我的表单有一个不寻常的问题(这里是精简版): (function($){ $("form").submit(function(){ alert('Ch
作为我论文论文的一部分,我构建了一个“机器人”,它会抓取 C 语言编程类(class)的官方论坛并搜索常见问题以便发布回复。我现在必须模拟登录才能发布适当的回复。登录表单如下: !-- 登录表单 --
我正在尝试创建一个在后台运行的小脚本,并检查论坛上是否有新消息(使用 phpBB3)。由于许多子论坛需要登录用户的权限才能查看,因此我创建了一个脚本,该脚本会向服务器发送后请求以先登录。 该脚本目前已
我是一名优秀的程序员,十分优秀!