Skip to content

iOS packet tunnel provider limit #4422

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
iambabyninja opened this issue Feb 21, 2025 · 57 comments
Open

iOS packet tunnel provider limit #4422

iambabyninja opened this issue Feb 21, 2025 · 57 comments

Comments

@iambabyninja
Copy link
Member

Original discussion: #4398

Good afternoon, dear members of our community!

Specifically, we know for certain that in the current versions of iOS, we have the following memory limitations:

Provider Limit (MiB)
packet tunnel 50
app proxy 15
filter control 50
filter data 50
DNS proxy 15
app push 24

In our case, Xray is a network process limited to 50MB. It reads geo files and then operates with the read content.

Unfortunately, with the current implementation of geofiles in our core, where all categories are in one large file, we often encounter the inability to even simply start the tunnel on an Apple device.
In particular, with the new geolocation files that we received from our partners, the file sizes have become significantly larger, which means that we cannot load them into memory.

A simple example (Loyalsoldier geosite):
image
None of the first four categories, if set in the routing rules, will allow the tunnel to start.

This also applies to geo files with CIDR (Loyalsoldier geoip)
Simple example:
image

@RPRX , considering the memory constraints, perhaps we should explore refactoring the geofile handling code. We could draw inspiration from neighboring teams and implement a system that utilizes multiple smaller files instead of one monolithic file. This approach could effectively resolve the memory issues on Apple devices. What you think about this?

@patterniha
Copy link
Contributor

patterniha commented Feb 21, 2025

on the iOS(with 8 GB ram) and in the "streisand" app, in addition to Loyalsoldier's geo-ip and geo-site, I added another geo-site(iran.dat), but still no problem occurred.

@iambabyninja
Copy link
Member Author

@patterniha The RAM here is irrelevant; this is specifically about the packet tunnel provider.

Are you sure you’re using the latest files? As of now, the old v2fly files are still included by default in Streisand.

Which categories are you using? For 100% of users in the control group, categories like geosite:category-ads-all, geosite:cn, and others caused the tunnel to crash.

@patterniha
Copy link
Contributor

patterniha commented Feb 21, 2025

geoip:ir, geosite:category-ads, geosite:category-ir, ext:iran.dat:tld-ir
i replace default geoip and geosite with Loyalsoldier's geoip and geosite.
also added a new geosite(iran.dat)
and in the "streisand" settings i turn off memory limitation.

Although I did this about a month ago and now I don't have access to an iPhone to test again.

@patterniha
Copy link
Contributor

patterniha commented Feb 21, 2025

Do you mean that the problem is with the large size of the loyalsoldier and the previous default geo has no problem?
or do you mean that even the previous default geo has a problem because it is a single file?

@RPRX
Copy link
Member

RPRX commented Feb 21, 2025

Xray-core 做过优化只解析有需要的 categories,不过前提是先把整个 geo 文件加载到内存中,我看了下新的是 21.3MB

如果这部分要继续优化就只能逐块读取文件

@iambabyninja
Copy link
Member Author

iambabyninja commented Feb 21, 2025

@patterniha I have created two simple visualizers for new files:
https://geosite.marzban.dev
https://geoip.marzban.dev

You can check the categories you specified.

In this case, with all due respect, your comparison is not relevant.

The geosite:ads category contains 749 rules, and there are no issues loading them.
However, the geosite:ads-all category contains 65,565(!!!!) rules, and loading them causes the tunnel to crash.

The geosite:category-ir category contains 170 rules.
The geosite:cn category contains 94,767(!!!) rules.

@RPRX
Copy link
Member

RPRX commented Feb 21, 2025

还有我觉得 iOS 这种内存受限的设备上倒不必跟着 Xray-core 换 geofiles,应该去用一些精简版的 geofiles

@iambabyninja iambabyninja closed this as not planned Won't fix, can't repro, duplicate, stale Feb 21, 2025
@RPRX
Copy link
Member

RPRX commented Feb 21, 2025

We could draw inspiration from neighboring teams and implement a system that utilizes multiple smaller files instead of one monolithic file.

我不懂这个 inspiration from neighboring teams 指的是什么,Xray 早在 v1.1.4 就有了优化机制,v2fly 是抄 Xray 的做法但只字未提

https://github.com/XTLS/Xray-core/releases/tag/v1.1.4

https://github.com/v2fly/v2ray-core/releases/tag/v4.39.0

不过我刚看了下 v2fly 这个是直接对着 file 读而不是对着内存中的 file 读,可以省点瞬时内存,但仍不敌 unmarshal 后的内存占用

要想 unmarshal 后占的内存少点,只能使用精简版的 geofiles

还是说你指的是 sing-box 的 rule-sets?那个我还没看

@Fangliding
Copy link
Member

Fangliding commented Feb 21, 2025

"utilizes multiple smaller files instead of one monolithic file"
很明显说的是singbox的rule-sets 它是切成多个小文件 每次只读取需要的((((

@RPRX
Copy link
Member

RPRX commented Feb 21, 2025

原来 rule-sets 就是这个,刚看到那两张图我还想着要不切成 1331+260 个文件算了

其实不切文件也能先用 1MB 的缓存遍历整个文件并建立 index 索引的,然后要哪部分就读哪部分,如果 Golang 方便这么做的话

@RPRX
Copy link
Member

RPRX commented Feb 21, 2025

但是这样也就顶多省个瞬时内存,比如减小 20MB 这样,对 unmarshal 后还是没有帮助,还是需要用精简版的 geofiles

如果是为了控制在 iOS 的 50MB 限制内,最终还是不能使用大而全的 geofiles,“进一步省瞬时内存”的必要性就存疑了

@RPRX
Copy link
Member

RPRX commented Feb 21, 2025

因为即使启动阶段省下了 20MB,后面代理跑起来也需要内存、缓存,给个 20MB 不过分吧

如果“进一步省瞬时内存”后,启动阶段都吃了顶格 50MB 了,后面还有什么内存跑代理

@RPRX
Copy link
Member

RPRX commented Feb 21, 2025

这么说来现在的一次性把 21.3MB 加载到内存中更像是一种“探测”,如果这都跑不起来,即使先放你通过,后面肯定动不动就 crash

@RPRX
Copy link
Member

RPRX commented Feb 21, 2025

@Fangliding 你怎么看

@patterniha
Copy link
Contributor

if the problem is related to premise load of geofile --> It should crash even for smaller categories like "ir".

so the problem is related to size of big categories like "cn" or "ads-all".
and reading part by part doesn't help at all.

///

but 99% of the domains are less than 32 bytes length.
so even if we have 200000 domains the size should not exceed 7 MB.

so why does it occupy 21.3 MB?

@RPRX
Copy link
Member

RPRX commented Feb 21, 2025

21.3MB 是现在 geoip.dat 14.7MB 加 geosite.dat 6.6MB,不过它俩本身就有“压缩”,unmarshal 后会膨胀一些,没测算过膨胀的比例

不过 Xray 不是整个 unmarshal,而是先把这 21.3MB 读进内存,找到目标 categories 再 unmarshal,然后释放这 21.3MB,再跑代理

继续优化就是不一次性把 21.3MB 读进内存,但如我所说这样没什么意义,即使能先在 iOS 上跑起来了,后面跑代理的内存也不富裕

@RPRX
Copy link
Member

RPRX commented Feb 21, 2025

这里有数据:#4348 (comment)

但我也说过:#4348 (comment)

我觉得倒是可以看看 unmarshal 后的结构有没有优化空间

@patterniha
Copy link
Contributor

patterniha commented Feb 21, 2025

When loading geoste:cn, one takes up 27m of memory and the other takes up 36m.

why 27m and 36m?
according to #4422 (comment) we have less than 100000 rules.

So even if we assume that each domain is 32 bytes after decompression(although 99% of them are shorter) -->
32 * 100000 = 3.2m, so why 36m?

@RPRX
Copy link
Member

RPRX commented Feb 21, 2025

我觉得倒是可以看看 unmarshal 后的结构有没有优化空间

看了下,果然发现了大问题:

// Domain for routing decision.
type Domain struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
// Domain matching type.
Type Domain_Type `protobuf:"varint,1,opt,name=type,proto3,enum=xray.app.router.Domain_Type" json:"type,omitempty"`
// Domain value.
Value string `protobuf:"bytes,2,opt,name=value,proto3" json:"value,omitempty"`
// Attributes of this domain. May be used for filtering.
Attribute []*Domain_Attribute `protobuf:"bytes,3,rep,name=attribute,proto3" json:"attribute,omitempty"`
}

// IP for routing decision, in CIDR form.
type CIDR struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
// IP address, should be either 4 or 16 bytes.
Ip []byte `protobuf:"bytes,1,opt,name=ip,proto3" json:"ip,omitempty"`
// Number of leading ones in the network mask.
Prefix uint32 `protobuf:"varint,2,opt,name=prefix,proto3" json:"prefix,omitempty"`
}

这下就很抽象了

@RPRX RPRX reopened this Feb 21, 2025
@RPRX
Copy link
Member

RPRX commented Feb 21, 2025

@Fangliding 你试试把前三个 member 给删了并编译出来看看能少吃多少内存,还有 Domain Attribute 是干嘛的,实际有用到吗

而且它们的数组还是 []*router.Domain[]*router.CIDR,每条都多占个指针的内存

@RPRX
Copy link
Member

RPRX commented Feb 21, 2025

我试了下,直接把前三个 member 删了都能正常使用 geofiles

@Fangliding
Copy link
Member

attr是分组里的tag

@Fangliding
Copy link
Member

Fangliding commented Feb 21, 2025

这个rule的大小是小问题吧 最后都要被编译成它AC自动机里的trie树的

@RPRX
Copy link
Member

RPRX commented Feb 21, 2025

在路由使用 "geosite:cn" 的情况下,我的配置优化前静置内存占 15.1MB,优化后静置内存占 14.7MB

但是我发现了一个更严重的问题,如果 "geosite:cn" 出现了两次,内存占用会增加约 8MB

这应该是因为 IPCache[index] = &geoipSiteCache[index] = &geosite 没有生效,我需要想下当初为啥是这样的决定。。。

@RPRX
Copy link
Member

RPRX commented Feb 21, 2025

我需要想下当初为啥是这样的决定。。。

应该是因为关缓存只需关 geofiles 的缓存,而不应该关 unmarshal 后的内容的缓存,结果当初一起关了

#68 (comment)

#68 (comment)

这个rule的大小是小问题吧 最后都要被编译成它AC自动机里的trie树的

不过按 @Fangliding 的说法,如果这里 rule 的大小无关,可能是 GC 不及时的问题?因为优化前后确实有区别

并且产生了新问题,如果像 SiteCache[index] = &geosite 这样的缓存没用,该怎么复用?需要深入研究下路由了

还有我在想 unmarshal 时 IP 那个 []byte 应该是 clone 而不是取现有文件的切片吧。。。

@RPRX
Copy link
Member

RPRX commented Feb 21, 2025

或许先让 @yiguous 研究下

@yiguodev
Copy link
Collaborator

在 libXray 的早期版本中,实现了一种优化方案:在 packet tunnel 启动前,对用到的 geo 文件进行裁剪(只保留用到的规则)。具体可参见 geo_cut.go 。该文件已在后续更新中被删除。受限于当时的技术水平,此优化方案效果并不明显。

如果你们正在开发或改进你们的 iOS 客户端,此方案可以作为一种参考。

Domain Attribute 通常用于域名规则的特定地区分流,比如“geosite:apple@cn”,则只作用于 apple 相关的中国区域名。

In early versions of libXray, an optimization solution was implemented: before starting the packet tunnel, the geo files used were trimmed (only the rules used were retained). For details, please see geo_cut.go. This file has been removed in a subsequent update.

If you are developing or improving your iOS client, this solution can be used as a reference.

@Jolymmiles
Copy link

Jolymmiles commented Feb 21, 2025

When I worked with loading large files (100+ GB) over the network in Java, I used file streaming to disk instead of loading into RAM. Then I processed those large compressed files without unpacking (the uncompressed ones were 600-1000 GB).

Is it possible to use the streaming principle in Xray?

To restructure the file so that it can be read not entirely into RAM, but in chunks consisting of byte arrays or whatever is inside the .dat file?

Store meta information about the sections inside the file and access specific areas instead of reading everything and then searching for the required part.

The CPU load will be higher, but why not?

@Jolymmiles
Copy link

Do I understand correctly that if the rules specify domain:ru, there will be no pupa.ru, zalupa.ru in the RAM?

@Jolymmiles
Copy link

geosite:zalupa

Inside pupa.ru, ru

How will the core behave?

@Pro100gopher
Copy link

@RPRX Hello. My problem is not exactly on-topic, but it also concerns the 50MB memory limit on iOS.

When running the xhttp configuration (xhttp-reality, xhttp-tls, xhttp-tls-cdn) with default “extra” settings on iOS, memory usage exceeds 50MB at its peak on any client. I observed on a Mac that the app can consume up to 96MB. And this happens even with routing completely disabled.

In the case of xhttp-reality, using
“maxConcurrency”: “1”
helps a little, but memory usage still sometimes exceeds 50MB.

I check this by running the Speedtest app or opening the ipleak.net site. In these cases, memory usage grows significantly above the set limit.

So, here’s my question. Could you please advise if there are any client configuration settings that could help maintain stable xhttp usage on iOS?

@patterniha
Copy link
Contributor

patterniha commented Feb 21, 2025

@RPRX Hello. My problem is not exactly on-topic, but it also concerns the 50MB memory limit on iOS.

When running the xhttp configuration (xhttp-reality, xhttp-tls, xhttp-tls-cdn) with default “extra” settings on iOS, memory usage exceeds 50MB at its peak on any client. I observed on a Mac that the app can consume up to 96MB. And this happens even with routing completely disabled.

In the case of xhttp-reality, using “maxConcurrency”: “1” helps a little, but memory usage still sometimes exceeds 50MB.

I check this by running the Speedtest app or opening the ipleak.net site. In these cases, memory usage grows significantly above the set limit.

So, here’s my question. Could you please advise if there are any client configuration settings that could help maintain stable xhttp usage on iOS?

even with simple "ws" transport and not using geofiles, many users report that the VPN is constantly disconnected and they have to manually turn it on again.(now I realize it was because of the RAM.)

we are in 2025 and the age of artificial intelligence, but iOS has set a 50MB limit even on 8GB series!!!

@Fangliding
Copy link
Member

所以到底怎么办 在三个tg群发个投票?

@ccwater666
Copy link

还有我觉得 iOS 这种内存受限的设备上倒不必跟着 Xray-core 换 geofiles,应该去用一些精简版的 geofiles

https://raw.githubusercontent.com/Loyalsoldier/geoip/release/geoip-only-cn-private.dat
使用这个精简版的geoip后确实有一定的效果,但是在iphone se这种刚好可以用ios 15的机器上,还是启动一会就超内存限制了。在iphone8 ios16上已经勉强可以跑
在hev-socks5-tunnel和libxray中都设置了内存限制,但是好像限不住。

@ccwater666
Copy link

还有我觉得 iOS 这种内存受限的设备上倒不必跟着 Xray-core 换 geofiles,应该去用一些精简版的 geofiles

https://raw.githubusercontent.com/Loyalsoldier/geoip/release/geoip-only-cn-private.dat 使用这个精简版的geoip后确实有一定的效果,但是在iphone se这种刚好可以用ios 15的机器上,还是启动一会就超内存限制了。在iphone8 ios16上已经勉强可以跑 在hev-socks5-tunnel和libxray中都设置了内存限制,但是好像限不住。

Image

还是不行, 看多几个视频内存就超了。

我使用控制变量法分别测试了hev-sock5-tunnel和xray,

第一种
控制hev-sock5-tunnel在ios中运行, xray在我的mac电脑上运行, . 把tunnel的socks指定mac电脑上xray. 此时项目运行良好. 内存控制在20M左右

第二种,
控制xray在ios中运行, 然后把浏览器的socks指定ios的xray. 此时项目也运行良好, 内存控制在20M左右.

但是只要tunnel和xray都在ios中运行的时候, 内存就很快会超出. 况且我都分别针对tunnel和xray做了内存限制, 但是并没什么效果.

@RPRX
Copy link
Member

RPRX commented Mar 3, 2025

说实话就是 iOS 这个 50MB 的限制真的落后,但凡 100MB 都没这问题,什么年代了都,以前还是 15MB

具体到对内存占用的优化,大概等到我写的客户端上 iOS 时我才有动力,不然 core 优化、iOS 客户端卖钱,我闲的吗

所以现阶段要推动优化内存这件事更应当由各个 iOS 客户端来研究,欢迎 PR,或者你们找到哪里该优化,我直接写代码也很快

@RPRX
Copy link
Member

RPRX commented Mar 3, 2025

Xray 刚出前两年没什么 iOS 客户端,就是因为限制 15MB,后来改成了 50MB,iOS 客户端就雨后春笋一样出来了

2025 年了,是时候改成 100MB 了,我寻思全局就这一个 VPN 也不差这 50MB,或许你们给苹果发个邮件,提醒它更新下内存限制

@RPRX
Copy link
Member

RPRX commented Mar 3, 2025

看了群里的讨论,感觉欧盟还不够努力,再加把油

@yiguodev
Copy link
Collaborator

yiguodev commented Mar 3, 2025

以我开发时长两年半的经验来看,我觉得还是弃疗吧。对于 Xray-core,一般客户端的集成方案都是 tun2socks + Xray-core。这个方案里,tun2socks 通常要占用 10M。 虽然 hev-socks5-tunnel 关闭 multi-queue 可以达到 3M 以内,但是应该没人会选择不开吧。 如果我们再留 5-10M 的余量,那么我们至少要把 Xray-core 的内存优化 35M 以内。这是一个挑战。

还是等 ”尊贵的苹果大人“ 放开限制吧。根据苹果的尿性,鬼知道要等到哪年。 不过,万一呢?做人嘛,总要有点幻想。

https://developer.apple.com/forums/thread/73148?page=2

@ccwater666
Copy link

⚠️ XRAY错误日志: 2025/03/03 17:02:51.435171 [Warning] dep: [内存释放] <<<< 释放前状态 >>>>| 已分配内存: 19 MiB | 总分配内存: 79 MiB | 系统内存: 44 MiB | GC次数: 738 | 下次GC阈值: 19 MiB | 堆内存: 19 MiB | 堆对象: 110806 | 堆空闲: 1 MiB | 堆使用: 21 MiB | 栈内存: 17 MiB | 最后GC时间: 2025-03-03 17:02:51.231275
⚠️ XRAY错误日志: 2025/03/03 17:02:51.873224 [Warning] dep: [内存监控] 内存使用量接近警告阈值:44MB
⚠️ XRAY错误日志: 2025/03/03 17:02:52.741545 [Warning] dep: [内存释放] >>>> 释放后状态 <<<<| 已分配内存: 19 MiB | 总分配内存: 79 MiB | 系统内存: 44 MiB | GC次数: 740 | 下次GC阈值: 19 MiB | 堆内存: 19 MiB | 堆对象: 110168 | 堆空闲: 0 MiB | 堆使用: 21 MiB | 栈内存: 17 MiB | 最后GC时间: 2025-03-03 17:02:52.495445
⚠️ XRAY错误日志: 2025/03/03 17:02:52.741733 [Warning] dep: [GC统计] ----暂停次数: 740 | 最近暂停时间: [] | 总暂停时间: 3.057106478s
⚠️ XRAY错误日志: 2025/03/03 17:02:53.935367 [Warning] dep: [内存释放] <<<< 释放前状态 >>>>| 已分配内存: 20 MiB | 总分配内存: 80 MiB | 系统内存: 44 MiB | GC次数: 743 | 下次GC阈值: 20 MiB | 堆内存: 20 MiB | 堆对象: 113446 | 堆空闲: 0 MiB | 堆使用: 21 MiB | 栈内存: 17 MiB | 最后GC时间: 2025-03-03 17:02:53.791958
⚠️ XRAY错误日志: 2025/03/03 17:02:54.497766 [Warning] dep: [内存释放] >>>> 释放后状态 <<<<| 已分配内存: 19 MiB | 总分配内存: 80 MiB | 系统内存: 44 MiB | GC次数: 745 | 下次GC阈值: 20 MiB | 堆内存: 19 MiB | 堆对象: 111692 | 堆空闲: 0 MiB | 堆使用: 21 MiB | 栈内存: 17 MiB | 最后GC时间: 2025-03-03 17:02:54.396611
⚠️ XRAY错误日志: 2025/03/03 17:02:54.497958 [Warning] dep: [GC统计] ----暂停次数: 745 | 最近暂停时间: [] | 总暂停时间: 3.113432853s
⚠️ XRAY错误日志: 2025/03/03 17:02:54.963928 [Warning] dep: [内存监控] 内存使用量超过危险阈值:48MB,执行激进内存释放
⚠️ XRAY错误日志: 2025/03/03 17:02:55.584008 [Warning] dep: [内存释放] <<<< 释放前状态 >>>>| 已分配内存: 20 MiB | 总分配内存: 81 MiB | 系统内存: 48 MiB | GC次数: 746 | 下次GC阈值: 20 MiB | 堆内存: 20 MiB | 堆对象: 113607 | 堆空闲: 3 MiB | 堆使用: 21 MiB | 栈内存: 18 MiB | 最后GC时间: 2025-03-03 17:02:54.850798

经过这几天的测试我发现xray在ios15和ios16上的内存是无法及时释放的,但是ios17以上就没这个问题。 难道是要放弃ios17以下了?

@ccwater666
Copy link

Xray 刚出前两年没什么 iOS 客户端,就是因为限制 15MB,后来改成了 50MB,iOS 客户端就雨后春笋一样出来了

2025 年了,是时候改成 100MB 了,我寻思全局就这一个 VPN 也不差这 50MB,或许你们给苹果发个邮件,提醒它更新下内存限制

我也觉得苹果这个限制是够奇葩的了。但是有什么办法呢。

@RPRX
Copy link
Member

RPRX commented Mar 4, 2025

关于 []*router.Domain 我又研究了一下,它只出现在配置解析阶段,解析完就被扔掉了

不过我发现了一个优化点是 DomainMatcher 可以复用,即 "geosite:cn" 出现多次时不会额外增加内存占用

还有 RoutingRule 里的 Geoip []*GeoIPSourceGeoip []*GeoIP 看代码应该也是配置解析完就会被扔掉,没有被引用而占着内存

@RPRX
Copy link
Member

RPRX commented Mar 4, 2025

不过我发现了一个优化点是 DomainMatcher 可以复用,即 "geosite:cn" 出现多次时不会额外增加内存占用

GeoIPMatcher 也应当被复用,不过现在的问题是路由那里写的是数组,然后不同来源的规则被揉到了一起,想复用的话需要拆开放

@RPRX
Copy link
Member

RPRX commented Mar 4, 2025

以及 GeoIPMatcher 的结构感觉有点复杂了,这里应该有优化空间,至少能把内存占用优化掉 3/10

@ccwater666
Copy link

关于 []*router.Domain 我又研究了一下,它只出现在配置解析阶段,解析完就被扔掉了

不过我发现了一个优化点是 DomainMatcher 可以复用,即 "geosite:cn" 出现多次时不会额外增加内存占用

还有 RoutingRule 里的 Geoip []*GeoIPSourceGeoip []*GeoIP 看代码应该也是配置解析完就会被扔掉,没有被引用而占着内存

我这几天的测试好像都是用全局测试的, 下面是我测试用的配置。 按理跟统计相关东西应该不太会影响内存吧。

{
"policy" : {
"system" : {
"statsInboundUplink" : true,
"statsOutboundUplink" : true,
"statsOutboundDownlink" : true,
"statsInboundDownlink" : true
}
},
"dns" : {
"servers" : [
"103.164.223.68",
"182.16.160.186"
]
},
"inbounds" : [
{
"port" : 51517,
"listen" : "[::1]",
"settings" : {
"udp" : true
},
"protocol" : "socks",
"tag" : "socks",
"sniffing" : {
"enabled" : true,
"destOverride" : [
"http",
"tls"
]
}
},
{
"listen" : "127.0.0.1",
"protocol" : "dokodemo-door",
"settings" : {
"address" : "127.0.0.1"
},
"tag" : "metricsIn",
"port" : 51518
}
],
"stats" : {

},
"outbounds" : [
{
"protocol" : "vless",
"settings" : {
"vnext" : [
{
"address" : "test.XXXX.com",
"users" : [
{
"id" : "XXXXXXXXXXX",
"encryption" : "none",
"flow" : "xtls-rprx-vision"
}
],
"port" : 58375
}
]
},
"tag" : "vless-out",
"streamSettings" : {
"network" : "tcp",
"realitySettings" : {
"publicKey" : "XXXXXXXX",
"serverName" : "www.ebay.com",
"spiderX" : "/",
"shortId" : "",
"fingerprint" : "chrome"
},
"security" : "reality"
}
},
{
"tag" : "direct",
"protocol" : "freedom"
}
],
"routing" : {
"rules" : [
{
"type" : "field",
"outboundTag" : "metricsOut",
"inboundTag" : [
"metricsIn"
]
},
{
"type" : "field",
"outboundTag" : "vless-out",
"port" : "0-65535"
}
],
"domainStrategy" : "AsIs"
},
"log" : {
"loglevel" : "warning",
"access" : "/xray.log",
"error" : "
/xray_error.log",
"dnsLog" : true
},
"metrics" : {
"tag" : "metricsOut"
}
}

@ccwater666

This comment has been minimized.

@ccwater666

This comment has been minimized.

@ccwater666
Copy link

VPN连接成功的时候,内存占用在23M,这个时候没有访问任何网站的话,会一直稳定在这个, 打开第一个网站whoer.net. 内存占用就火速标升超过50M

@lucaslu81
Copy link

先叠个甲,我对xray的实现以及iOS开发都不太明了,但这个问题我确实遇到了,我自己用了一个解法,使得无需裁剪dat文件。
首页有两个东西我不知道说得对不对,一是对iOS来说,有个group的东西,原本是用于不同的target做通信和信息共享的,把site和ip文件放到这个group里去;二是对xray来说,在启动的时候可以设置一个系统变量还是什么的,可以指定dat文件的根目录,把这个根目录设置为group的dat文件的目录。这样就绕开了把dat文件放在packet tunnel导致内部爆炸的问题。 @iambabyninja

@ccwater666
Copy link

先叠个甲,我对xray的实现以及iOS开发都不太明了,但这个问题我确实遇到了,我自己用了一个解法,使得无需裁剪dat文件。 首页有两个东西我不知道说得对不对,一是对iOS来说,有个group的东西,原本是用于不同的target做通信和信息共享的,把site和ip文件放到这个group里去;二是对xray来说,在启动的时候可以设置一个系统变量还是什么的,可以指定dat文件的根目录,把这个根目录设置为group的dat文件的目录。这样就绕开了把dat文件放在packet tunnel导致内部爆炸的问题。 @iambabyninja

没错的,现在一般都是这么操作的, 把文件还有配置文件那些放到group目录中去。

@yiguodev
Copy link
Collaborator

libXray has added ThinGeoData function. Maybe it will help to reduce memory usage on start. Actually, I think it will not.

@yiguodev
Copy link
Collaborator

根据我的测试,当域名规则总量超过6000,VPN 内存占用更容易超过限制。所以如果你们为客户提供默认规则配置,可以适当控制用到的规则分类。

According to my test, when the total number of domain rules exceeds 6000, the VPN memory usage is more likely to exceed the limit. So if you provide customers with default rule configurations, you can appropriately control the rule categories used.

@afdde
Copy link

afdde commented Mar 12, 2025

看了群里的讨论,感觉欧盟还不够努力,再加把油

你不懂资本主义自由市场,苹果的系统 库克想怎么样就怎么样,欧盟政府没有权力管.EU极左死了,严重扰乱市场.

@yuhan6665
Copy link
Member

yuhan6665 commented May 12, 2025

读了一下这个帖子
我的想法是其实在客户端99%都只是在用cn我们可以在核心启动的时候把整个geosite 自动分割成文件 比如geosite-cn-a 然后只有使用到的才会装载到内存
进一步 可以做成lru的形式 超过设定的值之后自动把最老的给释放掉 这样客户端作者可以很容易用读取时间换更多内存

@Meo597
Copy link
Contributor

Meo597 commented May 13, 2025

我的想法是其实在客户端99%都只是在用cn

ip这块绝大多数客户端都在用cn、ir、ru这几个有墙国家的tag
其它国家的tag基本用不了,因为geoip依赖的maxmind根本不全

实际上这个issues只要让geoip把ir ru也像cn一样打包个单独的dat出来基本就够了
site同理,把高频使用且体积大的tag生成出独立dat

为此可以提交一个PR到geoip,只要改动几行就行非常简单


感觉没必要让每个xray实例都自己去割geodat,感觉代码会变得挺脏,应该fork geodat直接分割好

目前得显式指定切割好的文件来用ext:geoip-cn.dat
可以加个判断让geoip:cn更智能点自动转换成它

@ghost
Copy link

ghost commented May 16, 2025

确实router模块需要优化。geosite cn太大导致v2rayNG多次切换节点还得关闭应用清理内存。

@megasoheilsh
Copy link

megasoheilsh commented May 24, 2025

I tested the latest version of Xray ( happ , streinsand ) without any routing on iOS device (iPhone 16 Pro Max) After uploading 20–30 MB, the core crashes. The config uses xhttp tls xmux "maxConcurrency": "4-8" and WS over tls mux "concurrency": 8

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests