Post ARCcvKSwKFP4wcBXc0 by bgme@bgme.me
 (DIR) More posts by bgme@bgme.me
 (DIR) Post #ARCVM6Z5JkMU17JfCy by bgme@bgme.me
       2023-01-01T13:37:21Z
       
       0 likes, 0 repeats
       
       这两天在折腾 Synapse ,看了不少文档,在这里写一个吐嘈串。
       
 (DIR) Post #ARCVzYjGXNsMf0tKfQ by bgme@bgme.me
       2023-01-01T13:44:29Z
       
       0 likes, 0 repeats
       
       这两天看了一些 Synapse 的文档,今天又看了一下 Dendrite 文档,越发感觉自己被坑了。NekoSynapse 的安装文档上,只字不提系统的硬件需求,只是写了一些安装步骤。但是让我们打开 Dendrite 的文档[1],开头就写了 Requirements 。>  At an absolute minimum, Dendrite will expect 1GB RAM. For a comfortable day-to-day deployment which can participate in federated rooms for a number of local users, be prepared to assign 2-4 CPU cores and 8GB RAM — more if your user count increases.Dendrite 是使用GO语言新写的 Matrix 协议服务端实现。相较使用 Python 写的 Synapse ,使用GO编写的 Dendrite 在内存占用以及性能方面均有了大幅度的优化。但即使这样,Dendrite 对于资源的要求也是:内存最少1GB,如果想舒适的 Federate 的话, 内存至少8GB。另外,注意这仅仅是 Dendrite 服务占用的内存,并不包含 PostgreSQL 。如果 PostgreSQL 与 Dendrite 部署在同一台机器上,内存估计可能要16G起步。[1] https://matrix-org.github.io/dendrite/installation/planning#requirements
       
 (DIR) Post #ARCWGLiYAQqbEFYxZw by bgme@bgme.me
       2023-01-01T13:47:31Z
       
       0 likes, 0 repeats
       
       反正从各种角度来看,Matrix 对系统的要求都比 Mastodon 高多了。(从这里也可以看出 Synapse 安装文档中不写硬件需求的鸡贼之处。)另外,不光硬件要求到,存储空间占用也大,现在 PostgreSQL 中 Mastodon 占用了大约50GB,而没有什么人用的 Synapse 却占了60GB。反正就是坑。一个字:坑两个字:很坑三个字:非常坑
       
 (DIR) Post #ARCWNN11jv63HWYMGu by bgme@bgme.me
       2023-01-01T13:48:47Z
       
       0 likes, 0 repeats
       
       另外 Synapse 对 CPU 的利用也存在问题。如图,我现在跑 Synapse 的这台VPS是2C8G。但是请注意,CPU利用即使是高峰时期也只有50%多。也就是只能跑满一个CPU,即使另一个CPU明显很空闲。不知道是不是和 Python 的 GIL 有关。
       
 (DIR) Post #ARCWnHpDezVEiGO7TU by che@qoto.org
       2023-01-01T13:53:27Z
       
       0 likes, 0 repeats
       
       @bgme 贵站的matrix服务打算关停了吗?
       
 (DIR) Post #ARCX6VGhu0A5uPPOAi by bgme@bgme.me
       2023-01-01T13:56:57Z
       
       0 likes, 0 repeats
       
       @che 有点想关掉,毕竟没有什么人用,资源占用还不少。当然,开放注册,让 Matrix 用起来,多拉人头,摊平成本,也是另外一种解决办法。
       
 (DIR) Post #ARCXYbEpIhiuX1vU5g by tusooa@kazv.moe
       2023-01-01T14:01:54.181388Z
       
       0 likes, 0 repeats
       
       @bgme matrix是个协议,不同实现,对系统要求肯定也不一样。不能一概而论。
       
 (DIR) Post #ARCXncb0XDeN5QSqQ4 by che@qoto.org
       2023-01-01T14:04:44Z
       
       0 likes, 0 repeats
       
       @bgme 发博文为matrix应用写些宣传吧,让贵站的用户了解到有这样的应用,说不定能引些注册量如果你认为matrix是时之所趋,还是开着吧。
       
 (DIR) Post #ARCXwCCy0sWbqvJ9o8 by che@qoto.org
       2023-01-01T14:06:16Z
       
       0 likes, 0 repeats
       
       @bgme 表述不确,改宣传为介绍
       
 (DIR) Post #ARCZziWUWVkWqvFNrs by bgme@bgme.me
       2023-01-01T14:29:17Z
       
       0 likes, 0 repeats
       
       上条嘟文中提到,使用默认的宏(monolith)模式,只能跑满一个CPU,结合 top 中只看见一个 python 进程,可以确定是 GIL 的锅没跑了。(图一)当然官方也知道这个问题,于是有了 Worker 。(图二)按照官方文档的说法:> For small instances it is recommended to run Synapse in the default monolith mode. For larger instances where performance is a concern it can be helpful to split out functionality into multiple separate python processes. These processes are called 'workers', and are (eventually) intended to scale horizontally independently.小实例的话,直接用一开始的宏模式就OK了。但对于 larger 一些的实例,想要性能好就要上 Worker 了。你不是单进程受GIL影响吗?那好现在有Worker来帮你分担请求与负载了。这里必须要吐嘈一下。虽然说 Worker 是用来帮助 master 处理网络请求, 但是也并不是所有的网络请求都可以导到 Worker 上处理。只有一部分网络请求可以导到 Worker 上。为此,Synapse 文档特别贴心的提供了一个可以导入到 Worker 处理的请求的 path 正则列表。当看到这长长的、一页写不下的 path 正则列表时(图三),我的内心是这样的 :aru_0080: :aru_0080: :aru_0010: 。
       
 (DIR) Post #ARCa5AO0M9nKiTsNZA by bgme@bgme.me
       2023-01-01T14:30:19Z
       
       0 likes, 0 repeats
       
       数了一下,也不是**特别**多,没有上百条,也就是63条。
       
 (DIR) Post #ARCaBzpbzsDW0b2tpA by bgme@bgme.me
       2023-01-01T14:31:33Z
       
       0 likes, 0 repeats
       
       然后问题来了。Synapse 官方并没有提供一个供人参考的 nginx 配置文件。总之,这长长的 path 正则给你了,怎么将这些正则变成配置文件,那就是你的事了。
       
 (DIR) Post #ARCaE87EASjwHSIpbk by bgme@bgme.me
       2023-01-01T14:31:57Z
       
       0 likes, 0 repeats
       
       还好我用的是 Caddy ,写了一个简单的 python 脚本将这些正则转换成 caddy match json 了。
       
 (DIR) Post #ARCb0efcQvYD9BWlpQ by everpcpc@douban.city
       2023-01-01T14:40:39Z
       
       0 likes, 0 repeats
       
       @bgme 干点人事吧……不能直接就 proxy ^/_matrix/client/ 和 ^/_matrix/federation/ 吗 :ac_classic02:
       
 (DIR) Post #ARCbEyQllFJ4UHPRy4 by bgme@bgme.me
       2023-01-01T14:43:18Z
       
       0 likes, 0 repeats
       
       另外 Synapse 官方的 Worker 文档也有一些写的不太清楚。https://matrix-org.github.io/synapse/latest/workers.html它文中的 Worker configuration 一节,给出的 example 只有 worker 独有的部分,我一开始还以只 worker 一节真的只有这么短。但实际测试,退出报错了几次之后,才发现又被坑了。worker 实际的配置文件 = 标准 homeserver.yaml + worker 独有部分。最多只是改一改 listeners 。改好配置文件。配好 load balancing 。再设置好 Systemd 服务。然后就可以启动 worker 了。
       
 (DIR) Post #ARCbapFyYCn2PBmSlU by wuming@nerdculture.de
       2023-01-01T14:47:10Z
       
       0 likes, 0 repeats
       
       @bgme Dendrite已经好很多了,如果能接受放弃历史数据,可以现在就切换过去。对比Synapse和Mastodon就像是对比聊天软件和电子邮件,实时性、信息频度和加密级别都是两样的。站外信息延迟几个小时的Mastodon主站还能被推特流亡者接受;Matrix要是持续延时几分钟大概已经没人用了。话说回来,Elements这些人收入的大头是政府的funding,所以对性能上不是很积极也可以理解。
       
 (DIR) Post #ARCbqNneP0WDsmwy5g by bgme@bgme.me
       2023-01-01T14:50:03Z
       
       0 likes, 0 repeats
       
       @everpcpc monolith mode 时可以这样做,但使用了 worker 了就不能这样做了。一些请求 worker 无法处理,会直接500。比方说:^/_matrix/client/(r0|v3|unstable)/sendToDevice/我一开始就是 proxy ^/_matrix/client/ 和 ^/_matrix/federation/ 直接搞,然后发现一些请求 500 ,直接后果就是新设备登录无法 verify 了。然后又重新读了一遍文档,老老实实按照正则匹配请求了。没事,也就63条。
       
 (DIR) Post #ARCcvKSwKFP4wcBXc0 by bgme@bgme.me
       2023-01-01T15:02:08Z
       
       0 likes, 0 repeats
       
       @wuming > 话说回来,Elements这些人收入的大头是政府的funding,所以对性能上不是很积极也可以理解。我觉得你的理解可能有一些问题。bgme.me 建的这个 synapse 服务也快有两年了,性能方面,可以直观的体会出,现在的 synapse 的性能相比之前的版本已经有了很大的提高。另外开发 Dendrite ,这本来也是 matrix.org 为了提高服务性能所做的努力。按照 Dendrite 的FAQ,当 Dendrite 稳定之后,也就是发布 1.0 版本后,可能会提供从 Synapse 迁移至 Dendrite 的方案。https://matrix-org.github.io/dendrite/faq#is-there-a-migration-path-from-synapse-to-dendrite
       
 (DIR) Post #ARCd5NUvuIApFCuQiG by bgme@bgme.me
       2023-01-01T15:03:58Z
       
       0 likes, 0 repeats
       
       @tusooa matrix 协议现在就两种实现 Synapse、Dendrite,稳定可用的只有 Synapse。使用GO写的Dendrite对硬件要求都这么高,使用Python写的Synapse硬件要求只会更高。
       
 (DIR) Post #ARCe3fHMvSNTlbJNXE by everpcpc@douban.city
       2023-01-01T15:14:49Z
       
       0 likes, 0 repeats
       
       @bgme 给人一种屎山拆分微服务,但是又只拆了一部分的感觉 :bgm38: 然后它这个分布式的示意图也有点奇怪,看起来 worker 和 event persister 都还要去请求 main process,worker 又还都要去请求 event persister 的样子。 已经有了个 redis pub/sub 了,服务调用链还这么长,感觉作为一个开源项目后面已经很难维护下去了 :0b02:
       
 (DIR) Post #ARCe9a5L9LoxOZVSEq by bgme@bgme.me
       2023-01-01T15:15:56Z
       
       0 likes, 0 repeats
       
       @everpcpc 所以又用GO写了Dendrite。
       
 (DIR) Post #ARCeeJeIJEhNOdVlhY by everpcpc@douban.city
       2023-01-01T15:21:19Z
       
       0 likes, 0 repeats
       
       @bgme 看了下 Dendrite 的 sso 好像还没有 ready 的样子,有种要精简掉的感觉: https://github.com/matrix-org/dendrite/pull/2492#issuecomment-1337734365
       
 (DIR) Post #ARCfUXUg4yy9OTuoG8 by tusooa@kazv.moe
       2023-01-01T15:30:49.492737Z
       
       0 likes, 0 repeats
       
       @bgme 还有rust写的conduit更多的服务端实现列表有https://github.com/matrix-org/matrix.org/tree/master/gatsby/content/projects/servers
       
 (DIR) Post #ARCfds94fOii39GETI by bgme@bgme.me
       2023-01-01T15:32:34Z
       
       0 likes, 0 repeats
       
       @tusooa 多谢。是我想当然了。
       
 (DIR) Post #ARChbMxVqWRseimrnE by Candinya@nya.one
       2023-01-01T15:43:38.871Z
       
       0 likes, 0 repeats
       
       @bgme@bgme.me 是不是因为 trusted keyserver 里面没有把 matrix.org 去掉…这个选项的意思不知道是什么意思,但猜测可能是把目标服务器上所有用户的公钥预拉取一遍,因为开了之后体积瞬间膨胀,去掉之后再干净启动的实例似乎占用就不大((
       
 (DIR) Post #ARChbNVBpJO4LAXlHk by Candinya@nya.one
       2023-01-01T15:49:29.762Z
       
       0 likes, 0 repeats
       
       @bgme@bgme.me *表达可能有些歧义,我指的是在配置阶段就去掉,在初次启动和正式运行阶段都没有出现这个的,空间占用小;已经启动的实例不确定启动之后再去掉会不会释放空间(可能不会吧
       
 (DIR) Post #ARChbNv4H65TdQeQca by bgme@bgme.me
       2023-01-01T15:54:34Z
       
       0 likes, 0 repeats
       
       @Candinya 与 trusted keyserver  设置无关。trusted keyserver 是与 Matrix 网络信任机制相关,设计的挻巧妙的。明天如果有时间的话,可以来写一写。下面的是一些参考资料,如果有空的话可以看一看。https://spec.matrix.org/unstable/server-server-api/#retrieving-server-keyshttps://web.archive.org/web/20170702024706/https://perspectives-project.org/https://github.com/matrix-org/synapse/pull/6110https://github.com/matrix-org/synapse/blob/044fa1a1de3c954f247a98c0ce8f734c675a5efb/synapse/crypto/keyring.py#L155-L161https://github.com/matrix-org/synapse/pull/13999https://github.com/matrix-org/synapse/issues/6086
       
 (DIR) Post #ARDntLGleyK3Vmhsm0 by l2dy@mstdn.io
       2023-01-02T04:39:41Z
       
       0 likes, 0 repeats
       
       @bgme 然而 Synapse has ended up increasingly focusing on large-scale deployments, Dendrite has ended up pursuing smaller instances (which is ironic, given originally it was meant to be the other way round!). https://matrix.org/blog/2022/12/25/the-matrix-holiday-update-2022
       
 (DIR) Post #ARN7tEBtiyxh41I7JA by bgme@bgme.me
       2023-01-06T16:36:14Z
       
       0 likes, 0 repeats
       
       折腾了几天 Matrix ,成功加入 #matrix:matrix.org 房间,我感觉已经什么都不怕了。再和其它 Matrix 实例站长交流之后,对于 Worker 也有了一点点经验。Matrix 文档中给中的这些路径正则,只是说这些请求可以被 Worker 处理,但这并不代表你一定要将这些请求都分散出去处理。对于低硬件的小实例而言,基本上就是哪痛医哪,哪些请求消耗太大,只需要将这些请求分担到单独的Worker上就可以了。在这些说一下,bgme.me Synapse 服务器的状况。硬件:2C8G 的 Hetzner VPS 软件:服务器上跑了三个 Synapse 进程,main、generic-worker、federation-sender。Sync 请求 、messages 分页请求以及 typing、receipts、presence stream 被交给 generic-worker 处理。^/_matrix/client/(r0|v3)/sync$^/_matrix/client/(api/v1|r0|v3)/events$^/_matrix/client/(api/v1|r0|v3)/initialSync$^/_matrix/client/(api/v1|r0|v3)/rooms/[^/]+/initialSync$^/_matrix/client/(api/v1|r0|v3|unstable)/rooms/.*/messages$^/_matrix/client/(api/v1|r0|v3|unstable)/rooms/.*/typing^/_matrix/client/(r0|v3|unstable)/rooms/.*/receipt^/_matrix/client/(r0|v3|unstable)/rooms/.*/read_markers^/_matrix/client/(api/v1|r0|v3|unstable)/presence/其余请求均直接导入 main 进程。federation-sender 不处理 HTTP 请求,专心向其它实例发送 federation event。除了这三个 synapse 进程,同一台机器上还跑着 mautrix-telegram 桥以及 matrix-media-repo 。图一、图二是加入 #matrix:matrix.org 房间后的资源占用情况。图三是 #matrix:matrix.org 房间加入前后的服务器流量对比。另外,给一个大实例(也许只能叫中等实例)的硬件配置以供参考。envs.net 实例8k用户1 cpu with 8 cores and 16 threats. (AMD Ryzen 7 3700X)96G RAM图四是 envs.net 实例的内存使用情况。另外 envs.net 实例全部 matrix 配置可以在这个 git 仓库找到。https://git.envs.net/envs/matrix-conf/src/branch/master仓库里包含   matrix-synapse 、 matrix-media-repo 、 matrix-synchrotron-balancer 、coturn、postgresql、nginx、prometheus 全套配置文件,非常具有参考价值。当然 envs.net 就真是老老实实,每个 path regular expressions 都写了一个 location。
       
 (DIR) Post #ARN8vGF1AkMVxLHfLU by bgme@bgme.me
       2023-01-06T16:47:47Z
       
       0 likes, 0 repeats
       
       另外,如果你想使用 matrix ,强烈不建议选择 matrix.org 实例,matrix.org 实例实在是太大了,人数也太多了,情能欠佳。外加 matrix.org 已经被 GFW 屏蔽。从各个方面而言,都不建议使用 matrix.org 实例。https://joinmatrix.org/servers/这是一份公共 Matrix 实例列表。另外,本站 Mastodon 用户可以通过 https://chat.bgme.bid/#/login ,点击下方按钮,一键全自动登入使用。bgme.me 的 Matrix 实例建有 Matrix-Telegram 桥,可以桥接 Matrix 房间。也可以通过 Matrix 登录 Telegram 帐户,通过 Matrix 收发你 Telegram 帐户的信息。
       
 (DIR) Post #ARN9zo7DGriS7xMh0q by bgme@bgme.me
       2023-01-06T16:59:49Z
       
       0 likes, 0 repeats
       
       同样式联邦式网络,Matrix 在管理方面真是先进 Mastodon 太多。Mastodon 还在讨论 #fediblock  时,Matrix 已经有从创建发布管理规则,跨站订阅全流程 #fediblock 工具了。https://github.com/matrix-org/mjolnir/另外,在翻看 Synapse 文档时发现 Synapse 竟然还支持 shadow ban ,可谓是相当……https://matrix-org.github.io/synapse/latest/admin_api/user_admin_api.html#controlling-whether-a-user-is-shadow-banned
       
 (DIR) Post #ARNA6WDeCu2ieNZhnU by bgme@bgme.me
       2023-01-06T17:01:02Z
       
       0 likes, 0 repeats
       
       @tchaikovearth 欢迎分享。另外如果想来 bgme.me 的 Matrix 实例,也可以向我要邀请链接。
       
 (DIR) Post #ARNph2n2gP7iDFfLCy by sadalsuud@bgme.me
       2023-01-07T00:47:03Z
       
       0 likes, 0 repeats
       
       @bgme 桥接tg也太好了!!!速用
       
 (DIR) Post #ARNwLma4S7sTXSPJlw by SWwind@kazv.moe
       2023-01-07T01:10:44.199633Z
       
       0 likes, 0 repeats
       
       @bgme 这是matrix的功能还是synapse的功能?
       
 (DIR) Post #ARNwLnC0B6DdR69btY by bgme@bgme.me
       2023-01-07T02:01:38Z
       
       0 likes, 0 repeats
       
       @SWwind Moderation policy lists 是 Matrix 协议里的东西。https://spec.matrix.org/v1.5/client-server-api/#moderation-policy-listsshadow ban 就协议里没有,应该是 Synapse 自己的实现。
       
 (DIR) Post #AROVIvC3THoJmFXs6C by sadalsuud@bgme.me
       2023-01-07T08:33:18Z
       
       0 likes, 0 repeats
       
       @bgme 请问 :blobcatmeltcry: 要如何通过bgme的matrix登录tg呀?
       
 (DIR) Post #AROaF2zv0rgcatqBGa by bgme@bgme.me
       2023-01-07T09:28:38Z
       
       0 likes, 0 repeats
       
       @sadalsuud 这个你提醒我了。我刚想说,自动加入的公告房间里说,但转念一想,那个房间也只是最近才搞出来的东西。以前注册的 BGME 亲友应该是没加这个房间。已经邀请你加入公告房间了。初始空间#home:bgme.me公告房间#welcom:bgme.me
       
 (DIR) Post #AROah7uSLOmxw7ftxo by bgme@bgme.me
       2023-01-07T09:33:42Z
       
       0 likes, 0 repeats
       
       @sadalsuud 我这就去发一个公告。
       
 (DIR) Post #AROdm93pn6C4ok97Im by ps@wxw.moe
       2023-01-07T10:08:12Z
       
       0 likes, 0 repeats
       
       @bgme :anenw11:感谢分享
       
 (DIR) Post #ARUyI4GJzawFIvRgjw by Miaomiao@o3o.ca
       2023-01-10T11:26:20Z
       
       0 likes, 0 repeats
       
       @bgme