im 选型

openfire + hazelcast 插件
看了下 这片文章 https://blog.csdn.net/zpf336/article/details/70821160 有以下想法

第一点 ,hazelcast 这货基于 内存分片, 看了hazelcast 架构表示很疑惑 , 就算是基于堆外内存,你在添加以及删除节点时候 ,这个集群是会重分片的 , 如果你的堆外内存很大 ,这时候 ,集群不能工作的时间会很长 ,当然 你可以做另外一件事情 对副本进行拷贝 ,依然提供服务 ,这样又有数据一致性问题 。 所以 你肯定会停

第二点 内存 不够了 我必须增加 instance 数量 来扩展 , jvm 堆外最大内存是有限制的 ,你应该做不到 动态变更jvm 堆外最大内存能力吧 ,那么 你只有 扩张你了集群了 。但这时候 可能会有 cpu 会很低

第三点 比如 271 分片 , 理论上 应该上是可以扩展到271个节点 , 每个节点只需要和 自己的副本节点 进行数据拷贝 。先不说271 分片的问题扩展性的问题 , 271个节点中的3个节点 都挂了,其中 分片1 和分片1的2个副本 , 这样整个集群还能用? 还能恢复? 用,可能可以用 , 这个分片上请求失败就行了 ,但是 恢复是不可能咯 , 想到的方法 只能和某一数据库结合或者是将数据写到文件中 ,从数据库或者文件中恢复一法 可行

既然 hazelcast 感觉上 不靠谱 那么我们是否有办法解决这个事情呢 。

第一点 我希望 某个 openfire 挂了(堆内,堆外 ,栈) ,不会引起数据的重分片
第二点 数据存储的内存不够 ,我希望不会挂
第三点 数据是可以恢复的

感觉上 就算 用redis 集群方案 替换 hazelcast ,靠谱的多 ,性能上 没有本地内存好 ,但是稳定性上 ,和openfire 隔离上 好得多 。 简单说 ,如果你能保证 hazelcast 扛的住 ,不影响openfire ,也不被openfire 影响 那 hazelcast 就是一个好的选择 ,否则 还是redis吧

openfire 还有一点问题 ,如果开发自己的业务 ,我必须在openfire 项目写插件 或者改源码的方式去实现 。如果插件有性能问题 ,也会影响到openfire 。 如果业务上能够切分出去就好了 。 我自己的想法是 通过kafka 把业务 openfire 中抽出来 ,然后 openfire 这块 不涉及任何的状态维护,不直接和缓存打交道 ,openfire 变成了一个xmpp 网关了 , 只处理 协议以及io通讯问题 ,业务由业务专门负责。 哪里不够扩展哪里。 kafka 可以作为缓冲 。但是延时会高一些 , 至少不会冲垮 ,后端的业务 。
有没有 xmpp 网关呢 这个要找找 ,不需要改openfire 直接实现的网关 。

可能最后 还是看openfire 源码
业务的定义是什么
从 client1 到 client2 的 message 算是业务? , 如果 简单 的 从 一个socket接受消息 ,发到另一个socket 去
个人 觉得 , 不涉及到sql 操作 ,比如message 保存 这样的话 我觉得不算 。
比如说 我要做消息过滤 , 这时候你要过滤message (简单过滤 ,不依赖于服务) , 我觉得这部分算 。
这样定义的话 。message 发送 , message 过滤 , message 保存 流程
openfire 对于在线消息 没有保存的吧 。message 过滤 应该属于 同步流程 , message 保存 可以做成异步 不阻塞 openfire

看看 session 吧

/*
 * Copyright (C) 2005-2008 Jive Software. All rights reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.jivesoftware.openfire.session;

import org.jivesoftware.openfire.privacy.PrivacyList;
import org.jivesoftware.openfire.user.UserNotFoundException;
import org.xmpp.packet.Presence;

/**
 * Represents a session between the server and a client.
 *
 * @author Gaston Dombiak
 */
public interface ClientSession extends Session {

    /**
     * Returns the Privacy list that overrides the default privacy list. This list affects
     * only this session and only for the duration of the session.
     *
     * @return the Privacy list that overrides the default privacy list.
     */
    PrivacyList getActiveList();

    /**
     * Sets the Privacy list that overrides the default privacy list. This list affects
     * only this session and only for the duration of the session.
     *
     * @param activeList the Privacy list that overrides the default privacy list.
     */
    void setActiveList( PrivacyList activeList );

    /**
     * Returns the default Privacy list used for the session's user. This list is
     * processed if there is no active list set for the session.
     *
     * @return the default Privacy list used for the session's user.
     */
    PrivacyList getDefaultList();

    /**
     * Sets the default Privacy list used for the session's user. This list is
     * processed if there is no active list set for the session.
     *
     * @param defaultList the default Privacy list used for the session's user.
     */
    void setDefaultList( PrivacyList defaultList );

    /**
     * Returns the username associated with this session. Use this information
     * with the user manager to obtain the user based on username.
     *
     * @return the username associated with this session
     * @throws UserNotFoundException if a user is not associated with a session
     *      (the session has not authenticated yet)
     */
    String getUsername() throws UserNotFoundException;

    /**
     * Returns true if the authetnicated user is an anonymous user or if
     * the use has not authenticated yet.
     *
     * @return true if the authetnicated user is an anonymous user or if
     * the use has not authenticated yet.
     */
    boolean isAnonymousUser();

    /**
     * Flag indicating if this session has been initialized once coming
     * online. Session initialization occurs after the session receives
     * the first "available" presence update from the client. Initialization
     * actions include pushing offline messages, presence subscription requests,
     * and presence statuses to the client. Initialization occurs only once
     * following the first available presence transition.
     *
     * @return True if the session has already been initializsed
     */
    boolean isInitialized();

    /**
     * Sets the initialization state of the session.
     *
     * @param isInit True if the session has been initialized
     * @see #isInitialized
     */
    void setInitialized( boolean isInit );

    /**
     * Returns true if the offline messages of the user should be sent to the user when
     * the user becomes online. If the user sent a disco request with node
     * "http://jabber.org/protocol/offline" before the available presence then do not
     * flood the user with the offline messages. If the user is connected from many resources
     * then if one of the sessions stopped the flooding then no session should flood the user.
     *
     * @return true if the offline messages of the user should be sent to the user when the user
     *         becomes online.
     */
    boolean canFloodOfflineMessages();

    /**
     * Returns true if the user requested to not receive offline messages when sending
     * an available presence. The user may send a disco request with node
     * "http://jabber.org/protocol/offline" so that no offline messages are sent to the
     * user when he becomes online. If the user is connected from many resources then
     * if one of the sessions stopped the flooding then no session should flood the user.
     *
     * @return true if the user requested to not receive offline messages when sending
     *         an available presence.
     */
    boolean isOfflineFloodStopped();

    /**
     * Obtain the presence of this session.
     *
     * @return The presence of this session or null if not authenticated
     */
    Presence getPresence();

    /**
     * Set the presence of this session
     *
     * @param presence The presence for the session
     */
    void setPresence( Presence presence );

    /**
     * Increments the conflict by one and returns new number of conflicts detected on this session.
     *
     * @return the new number of conflicts detected on this session.
     */
    int incrementConflictCount();

    /**
     * Indicates, whether message carbons are enabled.
     *
     * @return True, if message carbons are enabled.
     */
    boolean isMessageCarbonsEnabled();

    /**
     * Enables or disables <a href="http://xmpp.org/extensions/xep-0280.html">XEP-0280: Message Carbons</a> for this session.
     *
     * @param enabled True, if message carbons are enabled.
     * @see <a href="hhttp://xmpp.org/extensions/xep-0280.html">XEP-0280: Message Carbons</a>
     */
    void setMessageCarbonsEnabled(boolean enabled);
}

ClientSession 保存了联系人列表 ,在线列表 ,当前是否在线 ,是否匿名用户 ,是否所有设备是否支持离线发消息 ,离线接收消息 等等

这里有个问题 ,比如说 集群的负载均衡 ,用户1 登陆 在instance1 , 用户登陆instance2 ,这时候 用户1 给用户2 发消息 ,也就是说 instance1 必须知道用户2在instance2上 ,把消息转发给用户2 openfire session 是绑定连接的 , 连接这块 是没法共享的 , 但除连接以外的状态 是可以共享的 。

hazelcast 这种处理session的方式 , 每个instance 都会有它的副本 。 能不能撑的住 就看同时在线用户数 ,以及 jvm 内存能不能扛得住

所以 openfire 这种 架构体系 , 非要 把session状态 放到jvm 内存中 。 这是最大的问题。 一个应用 不可能搞定所有事 。

怎么去优化呢
1.可以通过插件拦截器 拦截所有 packet , 对于 指定业务 , 能异步处理 最好异步处理 。不能异步处理的业务 必须确保没有性能问题 。
2.缓存框架 这块 ,暂时不知道 怎么动, 看源码再说 ,如果还是用 hazelcast ,必须做好告警
,比如堆内 ,堆外内存 已经使用了50% ,这时候 要下发邮件 短信的方式 告知业务负责人。以防有变
3.如果缓存 框架 重构 , 需要很多的工时的 ,难度也很大 。

准备尝试利用 hazelcast 集群的能力 ,数据存储替换成redis 写个demo 看下

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 199,711评论 5 468
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 83,932评论 2 376
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 146,770评论 0 330
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 53,799评论 1 271
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 62,697评论 5 359
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 48,069评论 1 276
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 37,535评论 3 390
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 36,200评论 0 254
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 40,353评论 1 294
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 35,290评论 2 317
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 37,331评论 1 329
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 33,020评论 3 315
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 38,610评论 3 303
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 29,694评论 0 19
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 30,927评论 1 255
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 42,330评论 2 346
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 41,904评论 2 341

推荐阅读更多精彩内容