v2ray / v2ray-core

A platform for building proxies to bypass network restrictions.
https://www.v2ray.com/
MIT License
45.27k stars 8.94k forks source link

[v2.40] [VMess] [mKCP] Unable to cap bandwidth (uplinkCapacity not working) #592

Closed S-Tsunemori closed 6 years ago

S-Tsunemori commented 6 years ago

I know this sounds strange but I'd like to make v2ray use less bandwidth.

Here's part of my server config: (I'm trying to limit bandwidth to 1MB/s)

    "streamSettings": {
      "network": "kcp",
      "kcpSettings": {
        "uplinkCapacity": 1,
        "downlinkCapacity": 100,

And here's part of my client config: (I have a very low Upload bandwidth, only around 200~300KB/s)

      "streamSettings": {
        "network": "kcp",
        "kcpSettings": {
          "uplinkCapacity": 0,
          "downlinkCapacity": 100,

Using this config, v2ray works but in (almost) full speed (~50Mbps tested with http://beta.speedtest.net/) I also tried to change downlinkCapacity on client but it didn't seem to make any difference.

Server: linux-64 v2.40 / Client: Windows-64 v2.40

daiaji commented 6 years ago

Trickle might be able to help you

apt-get install trickle
trickle -d 2048 -u 2048 python speedtest_cli.py --share
S-Tsunemori commented 6 years ago

@daiaji It seems Trickle only works for TCP stream not UDP stream, even if it works are you sure it's a good idea to apply 3rd-party bandwidth cap for mKCP? If I want to run another program I might as well just run kcptun.

The problem is uplinkCapacity setting doesn't seem to work. I tried to remove per-connection settings and use a global setting (server config):

  "transport": {
    "kcpSettings": {
      "uplinkCapacity": 1,
      "downlinkCapacity": 100,

Still didn't make any difference.

daiaji commented 6 years ago

@S-Tsunemori I can't test uploading, but my download test shows that at least the client's downlinkCapacity is OK The test method is by downloading http://cachefly.cachefly.net/100mb.test And I tested speedtest.net, too The results are similar to those previously encountered Speedtest.net doesn't seem accurate enough

server config

            "kcpSettings":{
                "uplinkCapacity":100,
                "downlinkCapacity":100
            }

client config 1

            "kcpSettings":{
                "uplinkCapacity":100,
                "downlinkCapacity":0
            }

Aaron Swartz

client config 2

            "kcpSettings":{
                "uplinkCapacity":100,
                "downlinkCapacity":1
            }

Aaron Swartz

client config 3

            "kcpSettings":{
                "uplinkCapacity":100,
                "downlinkCapacity":2
            }

Aaron Swartz

client config 4

            "kcpSettings":{
                "uplinkCapacity":100,
                "downlinkCapacity":10
            }

Aaron Swartz

client config 5

            "kcpSettings":{
                "uplinkCapacity":100,
                "downlinkCapacity":100
            }

Aaron Swartz

The result is not linear at all There are even obvious errors

But it seems to be effective

For accuracy, the experiment may be done in LAN

S-Tsunemori commented 6 years ago

@daiaji I'm trying to limit uplinkCapacity on server so yes, I am trying to limit download bandwidth. Also I have tried to set "downlinkCapacity": 1 on client, in fact I just tested again just now.

I don't think it's a problem with speedtest.net because I've seen the same behavior on other test sites (like http://speedtest.googlefiber.net/) or just http download using Chrome browser. During all these tests, I can confirm my download speed is much higher than 1MB/s by my router monitor page.

Could you double-check that uplinkCapacity/downlinkCapacity acturally works?

daiaji commented 6 years ago

@S-Tsunemori Yes Speed limit is often not so ideal Perhaps the KCP need for broadband waste But downlinkCapacity will be more or less effective At least me here May need more samples? So long let the Issues keep open Hope to have more people to see

DarienRaymond commented 6 years ago

It is normal that the capacity settings differ with the actual value. The settings are software estimation on the traffic, but there is no way for the software to know the actual traffic throughput.