Java 线程池 阻塞提交任务

场景

提交任务由单线程提交到线程池多线程处理,在线程池达到处理上线时可以在提交的线程阻塞等待。

方案

1.最常见的方案就是直接设置线程池的拒绝策略为 CallerRunsPolicy,当触发拒绝策略时,会将该任务直接在提交任务所在的线程直接运行该任务。这个方案有个小问题,当如果提交的任务负载很重导致提交任务的线程长时间阻塞,就会造成线程池的饥饿。

2.较可行但是有点恶心的方案,自定义阻塞策略在触发拒绝时获取任务队列阻塞提交。

public void rejectedExecution(Runnable r, ThreadPoolExecutor executor) {
    try {
        if (!executor.isShutdown()) {
            executor.getQueue().put(r);
        }
    } catch (InterruptedException e) {
        Thread.currentThread().interrupt();
        throw new RejectedExecutionException("interrupted", e);
    }
}

这个方案也有问题:

如果你只有一个线程提交任务,而且任务的执行时间不可控,这个方案是我找到的算靠谱的了。

千万别这样用,你永远不知道别人会咋用你的线程池,一不小心就上当了!!!

3.较一般可行不那么恶心方案,自定义任务队列,直接让offer、and方法也阻塞

public class LimitedQueue<E> extends LinkedBlockingQueue<E> 
{
    public LimitedQueue(int maxSize)
    {
        super(maxSize);
    }

    @Override
    public boolean offer(E e)
    {
        // turn offer() and add() into a blocking calls (unless interrupted)
        try {
            put(e);
            return true;
        } catch(InterruptedException ie) {
            Thread.currentThread().interrupt();
        }
        return false;
    }

}

这个方案其实挺完美的,但是唯一的问题就是线程池永远只会有coreSize个线程,在任务队列达到上限时就直接阻塞了=.=丧失了线程池的伸缩能力。

4.优雅比较可行的方案,自定义实现线程池,用信号量控制同时进入的线程,这个方案代码很完美,但是操蛋的是无法精确控制线程数量。

public class BoundedExecutor extends ThreadPoolExecutor{

    private final Semaphore semaphore;

    public BoundedExecutor(int bound) {
        super(bound, Integer.MAX_VALUE, 60L, TimeUnit.SECONDS, new SynchronousQueue<Runnable>());
        semaphore = new Semaphore(bound);
    }

    /**Submits task to execution pool, but blocks while number of running threads 
     * has reached the bound limit
     */
    public <T> Future<T> submitButBlockIfFull(final Callable<T> task) throws InterruptedException{

        semaphore.acquire();            
        return submit(task);                    
    }


    @Override
    protected void afterExecute(Runnable r, Throwable t) {
        super.afterExecute(r, t);

        semaphore.release();
    }
}
//这个方案也类似 他们问题也是一样的,就是任务执行完后线程并不是立马可用的,但semaphore释放了
class BlockingExecutor implements Executor {

    final Semaphore semaphore;
    final Executor delegate;

    private BlockingExecutor(final int concurrentTasksLimit, final Executor delegate) {
        semaphore = new Semaphore(concurrentTasksLimit);
        this.delegate = delegate;
    }

    @Override
    public void execute(final Runnable command) {
        try {
            semaphore.acquire();
        } catch (InterruptedException e) {
            e.printStackTrace();
            return;
        }

        final Runnable wrapped = () -> {
            try {
                command.run();
            } finally {
                semaphore.release();
            }
        };

        delegate.execute(wrapped);

    }
}

这个方案的问题就是

  • afterExecute这个方法不是线程执行完任务最后做的事情,也就是说线程执行完afterExecute还会要执行一些任务才能返回线程池,但是这个时候我们已经执行了semaphore.release(),任务进来以后发现没有线程可用又得创建一个线程!!
  • 这个方案只能实现coreSize==maxSize,如果你尝试将任务队列长度修改和信号量长度修改,你会发现由于问题1,你总会莫名其妙的就触发了拒绝策略了
  • 线程池里的线程总会比bound要多,而且如果你的任务很快完成(非常快那种),有可能创建非常多的线程。

Linux上使用Selenium运行有头浏览器

通常我们服务器vps是没有安装gui显示的,但是为了避免使用无头浏览器(很容易被识别),我们可以用Xvfb。

Xvfb

Xvfb是一个实现 X11 显示服务器协议的显示服务器。该程序将允许您以“无头”模式运行任何应用程序。基本上,这个程序不会在物理屏幕上输出 GUI,而是创建一个虚拟帧缓冲区并在那里“显示”UI。

安装

sudo apt-get install xvfb

使用

先启动一个xvfb服务 指定id,然后我们启动项目时也指定这个id运行

 
export DISPLAY=:7 指定变量
Xvfb -ac $DISPLAY -screen 0 1280x1024x8 //比如这样 启动一个服务 指定虚拟id是7  
//然后直接运行就可以 会根据环境变量找到xvfb服务的
 java -jar xxxx.jar

可以尝试这个脚本使用 https://gist.github.com/tsl0922/ab8d370a85653c4354ad
最好的方式就是启动一个xvfb服务 这样就可以直接使用有头浏览器了
创建 一个脚本 xvfb.sh 内容如下
#!/bin/bash

XVFB=/usr/bin/Xvfb
XVFBARGS="$DISPLAY -ac -screen 0 1024x768x16"
PIDFILE=${HOME}/xvfb_${DISPLAY:1}.pid
case "$1" in
  start)
    echo -n "Starting virtual X frame buffer: Xvfb"
    /sbin/start-stop-daemon --start --quiet --pidfile $PIDFILE --make-pidfile --background --exec $XVFB -- $XVFBARGS
    echo "."
    ;;
  stop)
    echo -n "Stopping virtual X frame buffer: Xvfb"
    /sbin/start-stop-daemon --stop --quiet --pidfile $PIDFILE
    echo "."
    ;;
  restart)
    $0 stop
    $0 start
    ;;
  *)
  echo "Usage: /etc/init.d/xvfb {start|stop|restart}"
  exit 1
esac
exit 0

启动方式 
bash xvfb.sh start

JackSon 注解笔记

超全的JackSon注解大全包含demo https://www.tutorialspoint.com/jackson_annotations/index.htm

  • @JsonProperty 属性注解 可以修改序列化别名、默认值、展示效果
  • @JsonView 属性和方法注解 可以在不同视图中显示不同的序列化
  • @JsonCreator 方法注解 控制序列化使用的构造函数
  • @JsonValue 属性注解 控制某属性作为序列化的唯一结果输出
  • @JsonUnwrapped 对象扁平化把子属性对象解构提取到根对象
  • @JsonTypeName 配合@JsonTypeInfo指定序列化时属性对应名称
  • @JsonTypeInfo 解决多态反序列化问题 这里的大佬总结的很好
  • @JsonSubTypes 解决多态序列化时,无法确认子类类型的问题
  • @JsonTypeIdResolver 多态序列化相关 这部分可以看这个大佬的总结
  • @JsonTypeId 指定序列化时的key值
  • @JsonRawValue 是否按照字面量序列化,就是序列化结果是字符”key”:”xxx”还是”key”:xxx
  • @JsonManagedReference, @JsonBackReference 解决循环引用 具体的案例看这里
  • @JsonInclude 可以实现根据条件过滤key或value值 比如隐藏所有null值不序列化
  • @JsonIgnoreType 标记在类上,所有以该类为类型的值都会被忽略
  • @JsonIgnoreProperties 标记在类上,控制该类哪些属性被隐藏,还可以控制遇到json字符串未知参数是否抛出异常 ignoreUnknown
  • @JsonIdentityReference @JsonIdentityInfo 解决循环引用问题 具体demo看这里 @JsonIdentityReference可以让第二次序列化的对象(存在循环引用的对象)序列化为它的id值,@JsonIdentityReference 设alwaysAsId=true会让对象直接序列化为它的id值
  • @JsonGetter 指定序列化时使用的方法,可用于定义非静态、无参数返回值(非 void)方法,用作逻辑属性的“getter”。它可以用作更通用 JsonProperty注释的替代方法(这是一般情况下的推荐选择)。Getter 是指在序列化具有该方法的类的 Object 实例时(可能继承自超类),通过该方法进行调用,并将返回值序列化为该属性的值。
  • @JsonFormat 序列化时指定格式,常用于各种时间格式
  • @JsonFilter 定义一个过滤器的名称 在序列化时根据该名称指定序列化器 具体demo看这里
  • @JsonAnySetter 该注解允许我们把一个可变的map属性作为标准属性, 在反序列过程中, 从Json字符串得到的属性值会加入到map属性中,可以用它来存不存在于类中的属性。
  • @JsonAnyGetter 该注解用于把可变的Map类型属性当做标准属性,和@JsonAnySetter一起使用
  • @JacksonInject 指定属性是注入的而不是从Json字符串中反序列化获取
  • @JsonAutoDetect 可以覆盖可见性,可以指定属性的可见性
  • @JacksonAnnotation,@JacksonAnnotationsInside 属于JackSon的元注解

@JsonProperty

注意:虽然官方文档说 该注解如果和@JsonIgnore一同使用,@JsonIgnore 则优先于此属性。但实际测试用发现如果两个注解同时存在,效果等同 READ_ONLY,序列化都能展示,反序化不能写入。


String value: 指定序列化key
String defaultValue: 指定key的默认值
boolean	required:是否必须,但请注意,从 2.6 开始,此属性仅用于 Creator 属性,以确保 JSON 中存在属性值:对于其他属性(使用 setter 或可变字段注入的属性),不执行验证,也就是说只和@JsonCreator一起使用时生效。
int index: 指定该字段排序
JsonProperty.Access access: 序列化权限控制 有下列四种

  • AUTO 自动确定此属性的读取和/或写入访问权限。
  • READ_ONLY 只能在序列化时读取,而在反序列化期间不能写入(设置)。
  • READ_WRITE 无论可见性规则如何,都将访问该属性以进行序列化(将值写为外部表示)和反序列化(从外部表示中读取值)。
  • WRITE_ONLY 只能被写(set)用于反序列化,而不会被读(get)在序列化时,即该属性的值不包含在序列化中。

序列化权限控制测试代码:MyTest.java

@NoArgsConstructor
@AllArgsConstructor
@Builder
@Data
public class MyTest {

    @JsonProperty(access = AUTO)
    public String myA;

    @JsonProperty(access = READ_ONLY)
    public String myB;

    @JsonProperty(access = WRITE_ONLY)
    public String myC;

    @JsonProperty(access = READ_WRITE)
    public String myD;

    public static void main(String[] args) throws JsonProcessingException {
        MyTest myTest = MyTest.builder().myA("A").myB("B").myC("C").myD("D").build();
        ObjectMapper mapper = new ObjectMapper();
        String toJson = mapper.writeValueAsString(myTest);
        System.out.println("=======预期打印======");
        System.out.println("{\"myA\":\"A\",\"myB\":\"B\",\"myC\":\"C\",\"myD\":\"D\"}");
        System.out.println("=======序列化打印=====");
        System.out.println(toJson);
        System.out.println("=======反列化打印=====");
        String fromJson = "{\"myA\":\"A\",\"myB\":\"B\",\"myC\":\"C\",\"myD\":\"D\"}";
        MyTest test = mapper.readValue(fromJson,MyTest.class);
        System.out.println(test);
    }
}
输出结果:
=======预期打印======
{"myA":"A","myB":"B","myC":"C","myD":"D"}
MyTest(myA=A, myB=B, myC=C, myD=D)
=======序列化打印=====
{"myA":"A","myB":"B","myD":"D"}
=======反列化打印=====
MyTest(myA=A, myB=null, myC=C, myD=D)

@JsonCreator

JackSon默认使用无参构造方法和set方法反序列对象,使用该注解可以指定JaskSon使用指定方法进行反序列化构造对象,可以标注在构造方法和静态工厂方法上。

@JsonView

@JsonView使用方法:

  1.使用接口来声明多个视图 例如下面这个 代码来自baeldung.com

public class Views {
    public static class Public {
    }

    public static class Internal extends Public {
    }
}
public class Item {
 
    @JsonView(Views.Public.class)
    public int id;

    @JsonView(Views.Public.class)
    public String itemName;

    @JsonView(Views.Internal.class)
    public String ownerName;
}

  2.在pojo的属性上指定视图

public class Item {
 
    @JsonView(Views.Public.class)
    public int id;

    @JsonView(Views.Public.class)
    public String itemName;

    @JsonView(Views.Internal.class)
    public String ownerName;
}

  3.在Controller方法上指定视图

@JsonView(Views.Internal.class)
@RequestMapping("/items/internal/{id}")
public Item getItemInternal(@PathVariable int id) {
    return ItemManager.getById(id);
}

4.直接进行序列化或反序列化时可以指定视图

@Test
public void whenUseJsonViewToDeserialize_thenCorrect() 
  throws IOException {
    String json = "{"id":1,"name":"John"}";

    ObjectMapper mapper = new ObjectMapper();
    User user = mapper
      .readerWithView(Views.Public.class)
      .forType(User.class)
      .readValue(json);

    assertEquals(1, user.getId());
    assertEquals("John", user.getName());
}

@JsonValue

@JsonView是jackson json中的一个注解,指定属性后序列化将只使用该属性值作为序列化接口(这个注解只能作用于一个属性上)。

@JsonUnwrapped

@JsonUnwrapped 对象扁平化 如果属性序列化后是一个对象 会将该属性的对象解构提取到根对象中。

@JsonTypeName

用于绑定被注释类所具有的逻辑名称的注释。与JsonTypeInfo(特别是JsonTypeInfo.use()属性)一起使用以建立对象名称和属性之间的关系,反序列化为父类时,用于确定该对象的具体类型,与@JsonSubTypes 直接标注在父类等效。

@JsonTypeInfo

用于多态类型处理

Class<?> defaultImpl 指定默认的反序列化类型,当反序列对象无法映射到现在有的指定类型时会使用它进行反序列化。

JsonTypeInfo.As include 指定类型标识信息的展示方式。
有下列5种可选值 下面的测试结果使用的注解是@JsonTypeInfo(use= JsonTypeInfo.Id.NAME)

PROPERTY 使用单个可配置属性的包含机制,与实际数据(POJO 属性)一起作为单独的元属性包含在内。,这个属性的值由 @JsonTypeInfo注解的property确定,否则就使用不同use情况下的默认值(@class、@c、@type)。

@JsonTypeInfo(use= JsonTypeInfo.Id.NAME,
            include = JsonTypeInfo.As.PROPERTY )
结果:
=======未配置注解打印======
{"myA":"A","myB":"B","myC":"C","myD":"D"}
=======配置注解打印=======
{"@type":"MyTest","myA":"A","myB":"B","myC":"C","myD":"D"}

EXISTING_PROPERTY 与PROPERTY区别在于,该注解在序列化时不会输出标识符,反序列流程根PROPERTY相同。

EXTERNAL_PROPERTY 只作用于属性上,把子属性的标识符提升到根对象里,具体使用场景没搞明白。

WRAPPER_OBJECT 包裹在一个对象中,相当于在外层创建一个父对象 {标识符:{原本的对象}} 用一个大对象包住

@JsonTypeInfo(use= JsonTypeInfo.Id.NAME,
            include = JsonTypeInfo.As.EXTERNAL_PROPERTY )
结果:
=======未配置注解打印======
{"myA":"A","myB":"B","myC":"C","myD":"D"}
=======配置注解打印=======
{"MyTest":{"myA":"A","myB":"B","myC":"C","myD":"D"}}

WRAPPER_ARRAY 包裹在一个数组中。

@JsonTypeInfo(use= JsonTypeInfo.Id.NAME,
            include = JsonTypeInfo.As.WRAPPER_ARRAY )
结果:
=======未配置注解打印======
{"myA":"A","myB":"B","myC":"C","myD":"D"}
=======配置注解打印=======
["MyTest",{"myA":"A","myB":"B","myC":"C","myD":"D"}]

JsonTypeInfo.Id use 指定在序列化时类型标识信息展示的值。
有下列5种可选值

CLASS 意味着使用完全限定的 Java 类名作为类型标识符。

测试结果:可以看到序列化对象多了一个 @class key,而且其值为全限定类名。(若不指定property则默认为@class

=======未配置注解打印======
{"myA":"A","myB":"B","myC":"C","myD":"D"}
=======配置注解打印========{"@class":"com.example.demo.bean.MyTest","myA":"A","myB":B,"myC":"C","myD":"D"}

CUSTOM 意味着键入机制使用自定义处理,可能具有自定义配置。这个注解需结合property属性和@JsonTypeIdResolver一起使用,指定类标识符的值。

@JsonTypeInfo(use = JsonTypeInfo.Id.CUSTOM, property = "type")
@JsonTypeIdResolver(JacksonTypeIdResolver.class)
实现TypeIdResolver接口 自定义序列化流程

MINIMAL_CLASS 表示使用具有最小路径的 Java 类名作为类型标识符,多了一个”@c“字段,其值为最小路径类名。(若不指定property则默认为@c

=======未配置注解打印======
{"myA":"A","myB":"B","myC":"C","myD":"D"}
=======配置注解打印=======
{"@c":".MyTest","myA":"A","myB":"B","myC":"C","myD":"D"}

NAME 表示使用逻辑类型名作为类型信息;然后需要将名称单独解析为实际的具体类型(类),多了一个”@type”字段,其值为类名。(若不指定property则默认为@type

=======未配置注解打印======
{"myA":"A","myB":"B","myC":"C","myD":"D"}
=======配置注解打印=======
{"@type":"MyTest","myA":"A","myB":"B","myC":"C","myD":"D"}

NONE 这意味着不包含显式类型元数据,并且键入纯粹是使用上下文信息完成的,可能会增加其他注释。

=======未配置注解打印======
{"myA":"A","myB":"B","myC":"C","myD":"D"}
=======配置注解打印=======
{"myA":"A","myB":"B","myC":"C","myD":"D"}

String property 指定类标识名称,在include=JsonTypeInfo.As.PROPERTY或use=JsonTypeInfo.Id.CUSTOM生效,其他情况使用默认的识别码名称。
注意:include=JsonTypeInfo.As.PROPERTY和property同时存在有个问题,如果POJO具有相同名称的属性,会出现两个!

@JsonSubTypes

用来列出给定类的子类,只有当子类类型无法被检测到时才会使用它,也可以在子类上直接使用@JsonTypeName 实现同等效果。

Sentinel 面板数据空白解决方案

博主最近不小心买了很多吃灰服务器,正好可以拿去Java微服务相关,基于选新不选旧原则,直接开始学习SpringCloud。学习的过程中,遇到过两次sentinel面板数据空白的问题,先说解决方案

1.部署sentinel服务器和部署微服务服务器必须要开放对应端口!!sentinel的实时监控是通过调用机器Adapter获取实时监控的。

2.时间和时区要一致!!!(博主的吃灰服务器主要是欧洲和美国的,但是部署的时候发现,sentinel只有微服务启动的时候才会显示实时监控,一段时间后就不显示了,这就是时间和时区不一致导致的)

迁移tomcat10 XXX cannot be cast to jakarta.servlet.Filter 解决方案

之前公司有个老项目(struts2+ibatis)的要升级到迁移tomcat10,结果死活无法起来。

看来下日志 报错都是 XXX cannot be cast to jakarta.servlet.Filter,搜了半天终于整出了解决方案。

报错原因是坑爹的tomcat10把javax.servlet-api名叫jaraka.servlet了(这不是蛋疼吗!!!)

解决方案有俩

1.修改代码,手动把包引用从 Javax.XXX改成 Jaraka.XXX 然后编译

2.使用apache官网提供的迁移工具 tomcat-jakartaee-migration 对编译后的项目处理一下,具体使用可以去看下项目的描述,一行命令就可以执行了。

这里提供一个现成的下载

具体使用方法:

如果是linux系统,进入bin目录,bash migrate.sh 旧项目(支持文件夹和war包) 生成的新项目(支持文件夹和war包),例如 bash migrate.sh old.war new.war。

如果是window系统,进入lib目录, java -jar jakartaee-migration-1.0.0.jar old new,跟上面差不多,脚本里就是执行的jakartaee-migration-1.0.0.jar。

ps:如果还不能启动,看看原本项目中pom.xml的javax.servlet-api依赖范围scope是否改成了provided,如果没有还是会有那个报错哦。

HostHatch 独立日优惠

因为Chia币的影响,储存机型都普遍涨价了,但这次普遍流量都给的很多,特别是nvme机。

两年付的性价比依旧可以的,购买方法:

1.注册账号存入资金 https://hosthatch.com/a?id=1837

2.点击下列的购买链接下单(要先预存余额才能购买),如果是两年付,需要额外发送工单获取两年付的特惠.

Storage (only available in Chicago – and very limited quantity):

1x 2.4+ GHz
512 MB RAM
250 GB disk
1 TB bandwidth
$15 per year
Pay for two years (+$7) – get doubled RAM and +9 TB free bandwidth
https://manage.hosthatch.com/billing/order/chi-250g-storage
1x 2.4+ GHz
1 GB RAM
1 TB usable storage
3 TB bandwidth
$40 per year
Chicago
Pay for two years – get doubled RAM and +20 TB free bandwidth
https://manage.hosthatch.com/billing/order/chi-1tb-storage/


NVMe plans (Europe – Amsterdam, Stockholm, Zurich, Oslo, Vienna, Warsaw, London, Madrid and Milan)

1 CPU core (12.5% dedicated, burstable up to 100%)
1 GB RAM
10 GB RAID-10 NVMe
1 TB bandwidth
$15 per year
Pay for two years – get doubled RAM, storage, and +5 TB free bandwidth
https://manage.hosthatch.com/billing/order/nvme1-ams
https://manage.hosthatch.com/billing/order/nvme1-sto
https://manage.hosthatch.com/billing/order/nvme1-zrh
https://manage.hosthatch.com/billing/order/nvme1-osl
https://manage.hosthatch.com/billing/order/nvme1-vie
https://manage.hosthatch.com/billing/order/nvme1-waw
https://manage.hosthatch.com/billing/order/nvme1-lon
https://manage.hosthatch.com/billing/order/nvme1-mad
https://manage.hosthatch.com/billing/order/nvme1-mil
2 CPU cores (50% dedicated, burstable up to 200%)
4 GB RAM
20 GB NVMe SSD
5 TB bandwidth
$30 per year
Pay for two years – get doubled RAM, storage, and +15 TB free bandwidth
https://manage.hosthatch.com/billing/order/nvme4-ams
https://manage.hosthatch.com/billing/order/nvme4-sto
https://manage.hosthatch.com/billing/order/nvme4-zrh
https://manage.hosthatch.com/billing/order/nvme4-osl
https://manage.hosthatch.com/billing/order/nvme4-vie
https://manage.hosthatch.com/billing/order/nvme4-waw
https://manage.hosthatch.com/billing/order/nvme4-lon
https://manage.hosthatch.com/billing/order/nvme4-mad
https://manage.hosthatch.com/billing/order/nvme4-mil
3 CPU cores (100% dedicated, burstable up to 300%)
8 GB RAM
40 GB NVMe SSD
10 TB bandwidth
$60 per year
Pay for two years – get doubled RAM, storage, and +20 TB free bandwidth
https://manage.hosthatch.com/billing/order/nvme8-ams
https://manage.hosthatch.com/billing/order/nvme8-sto
https://manage.hosthatch.com/billing/order/nvme8-zrh
https://manage.hosthatch.com/billing/order/nvme8-osl
https://manage.hosthatch.com/billing/order/nvme8-vie
https://manage.hosthatch.com/billing/order/nvme8-waw
https://manage.hosthatch.com/billing/order/nvme8-lon
https://manage.hosthatch.com/billing/order/nvme8-mad
https://manage.hosthatch.com/billing/order/nvme8-mil


NVMe plans (North America – Los Angeles, Chicago and New York):

1 CPU core (12.5% dedicated, burstable up to 100%)
1 GB RAM
10 GB RAID-10 NVMe
1 TB bandwidth
$15 per year
Pay for two years – get doubled RAM, storage, and +5 TB free bandwidth
https://manage.hosthatch.com/billing/order/nvme1-lax
https://manage.hosthatch.com/billing/order/nvme1-ny
https://manage.hosthatch.com/billing/order/nvme1-chi
2 CPU cores (50% dedicated, burstable up to 200%)
4 GB RAM
20 GB NVMe SSD
5 TB bandwidth
$30 per year
Pay for two years – get doubled RAM, storage, and +15 TB free bandwidth
https://manage.hosthatch.com/billing/order/nvme4-lax
https://manage.hosthatch.com/billing/order/nvme4-ny
https://manage.hosthatch.com/billing/order/nvme4-chi
3 CPU cores (100% dedicated, burstable up to 300%)
8 GB RAM
40 GB NVMe SSD
10 TB bandwidth
$60 per year
https://manage.hosthatch.com/billing/order/ams-16g-nvme
Pay for two years – get doubled RAM, storage, and +20 TB free bandwidth
https://manage.hosthatch.com/billing/order/nvme8-lax
https://manage.hosthatch.com/billing/order/nvme8-ny
https://manage.hosthatch.com/billing/order/nvme8-chi


NVMe plans (APAC – Hong Kong and Sydney):

1 CPU core (12.5% dedicated, burstable up to 100%)
1 GB RAM
10 GB RAID-10 NVMe
500 GB bandwidth
$15 per year
Pay for two years – get doubled RAM, storage, and bandwidth
https://manage.hosthatch.com/billing/order/nvme1-hkg
https://manage.hosthatch.com/billing/order/nvme1-syd
2 CPU cores (50% dedicated, burstable up to 200%)
4 GB RAM
20 GB NVMe SSD
1 TB bandwidth
$35 per year
Pay for two years – get doubled RAM, storage, and bandwidth
https://manage.hosthatch.com/billing/order/nvme4-hkg
https://manage.hosthatch.com/billing/order/nvme4-syd
3 CPU cores (100% dedicated, burstable up to 300%)
8 GB RAM
40 GB NVMe SSD
2 TB bandwidth
$65 per year
Pay for two years – get doubled RAM, storage, and bandwidth
https://manage.hosthatch.com/billing/order/nvme8-hkg
https://manage.hosthatch.com/billing/order/nvme8-syd


Bundles:

Choose any 7 locations, 1 VM per location:

1 CPU core (12.5% dedicated, burstable up to 100%)
1 GB RAM
10 GB RAID-10 NVMe
1 TB bandwidth
$65 per year

To order, login to your account with us, top up the credit, and open a sales ticket with the 7 locations of your choosing.
All locations bundle, 1 VM per location:

1 CPU core (12.5% dedicated, burstable up to 100%)
1 GB RAM
10 GB RAID-10 NVMe
1 TB bandwidth
$110 per year

To order, login to your account with us, top up the credit, and open a sales ticket.

[hetzner]2.49€ 20T流量vps测试

hetzner不用过多介绍了吧,世界一流大厂,大厂中的大厂,以便宜的拍卖机(独立服务器)和超级稳的服务闻名。

他家vps都是20T流量,只计入站不计出战,可以按小时支付(也就是说流量跑完可以删机重建),不过博主不推荐这么玩,容易被制裁。这家最狠的就是你可以一直跑满G口直到用光流量,完全不会限制。不过如果你超了20T流量账号的小鸡就会被一直限速百兆,只有一次解除限速的机会,所以还是多注意注意流量的状况,别不小心超了。

废话少说,直接开始跑分,博主买的是他家最便宜的2.49€的vps,是intel cpu的。

cpu性能属于intel正常水平,这个硬盘io可太猛了,而且网络竟然还是10G口的。

root@ubuntu-2gb-fsn1-1:~# curl -s https://raw.githubusercontent.com/masonr/yet-another-bench-script/master/yabs.sh | bash
# ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## #
#              Yet-Another-Bench-Script              #
#                     v2020-12-29                    #
# https://github.com/masonr/yet-another-bench-script #
# ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## #

Mon 12 Apr 2021 01:46:53 PM CEST

Basic System Information:
---------------------------------
Processor  : Intel Xeon Processor (Skylake, IBRS)
CPU cores  : 1 @ 2294.608 MHz
AES-NI     : ✔ Enabled
VM-x/AMD-V : ❌ Disabled
RAM        : 1.9 GiB
Swap       : 0.0 KiB
Disk       : 18.7 GiB

fio Disk Speed Tests (Mixed R/W 50/50):
---------------------------------
Block Size | 4k            (IOPS) | 64k           (IOPS)
  ------   | ---            ----  | ----           ---- 
Read       | 121.29 MB/s  (30.3k) | 1.21 GB/s    (18.9k)
Write      | 121.61 MB/s  (30.4k) | 1.22 GB/s    (19.0k)
Total      | 242.90 MB/s  (60.7k) | 2.43 GB/s    (38.0k)
           |                      |                     
Block Size | 512k          (IOPS) | 1m            (IOPS)
  ------   | ---            ----  | ----           ---- 
Read       | 2.37 GB/s     (4.6k) | 2.45 GB/s     (2.3k)
Write      | 2.49 GB/s     (4.8k) | 2.61 GB/s     (2.5k)
Total      | 4.87 GB/s     (9.5k) | 5.06 GB/s     (4.9k)

iperf3 Network Speed Tests (IPv4):
---------------------------------
Provider        | Location (Link)           | Send Speed      | Recv Speed     
                |                           |                 |                
Clouvider       | London, UK (10G)          | 2.93 Gbits/sec  | 5.13 Gbits/sec 
Online.net      | Paris, FR (10G)           | 6.80 Gbits/sec  | 5.16 Gbits/sec 
WorldStream     | The Netherlands (10G)     | busy            | busy           
Biznet          | Jakarta, Indonesia (1G)   | 887 Mbits/sec   | 92.0 Mbits/sec 
Clouvider       | NYC, NY, US (10G)         | 1.45 Gbits/sec  | 2.01 Gbits/sec 
Velocity Online | Tallahassee, FL, US (10G) | 1.80 Gbits/sec  | 1.62 Gbits/sec 
Clouvider       | Los Angeles, CA, US (10G) | 1.14 Gbits/sec  | 1.09 Gbits/sec 
Iveloz Telecom  | Sao Paulo, BR (2G)        | busy            | busy           

iperf3 Network Speed Tests (IPv6):
---------------------------------
Provider        | Location (Link)           | Send Speed      | Recv Speed     
                |                           |                 |                
Clouvider       | London, UK (10G)          | 5.26 Gbits/sec  | 5.67 Gbits/sec 
Online.net      | Paris, FR (10G)           | busy            | 4.65 Gbits/sec 
WorldStream     | The Netherlands (10G)     | busy            | busy           
Clouvider       | NYC, NY, US (10G)         | 1.86 Gbits/sec  | 1.83 Gbits/sec 
Clouvider       | Los Angeles, CA, US (10G) | 1.13 Gbits/sec  | 1.06 Gbits/sec 

Geekbench 5 Benchmark Test:
---------------------------------
Test            | Value                         
                |                               
Single Core     | 664                           
Multi Core      | 662                           
Full Test       | https://browser.geekbench.com/v5/cpu/7385063

还不错,不过hz到国内不像netcup那样有直连,估计实际使用体验不会那么好。

 Superbench.sh -- https://www.oldking.net/350.html
 Mode  : [0;32mStandard[0m    Version : [0;32m1.1.7
 Usage : wget -qO- sb.oldking.net | bash
----------------------------------------------------------------------
 CPU Model            : Intel Xeon Processor (Skylake, IBRS)
 CPU Cores            : 1 Cores 2294.608 MHz x86_64
 CPU Cache            : 16384 KB 
 OS                   : Debian GNU/Linux 10 (64 Bit) KVM
 Kernel               : 4.19.0-14-amd64
 Total Space          : 1.6 GB / 19.1 GB 
 Total RAM            : 55 MB / 1947 MB (449 MB Buff)
 Total SWAP           : 0 MB / 0 MB
 Uptime               : 0 days 0 hour 23 min
 Load Average         : 0.31, 0.23, 0.17
----------------------------------------------------------------------
 CPU Model             : Intel Xeon Processor (Skylake, IBRS)
 CPU Cores             : 1
 CPU Frequency         : 2294.608 MHz
 CPU Cache             : 16384 KB
 Total Disk            : 19.1 GB (1.6 GB Used)
 Total Mem             : 1947 MB (54 MB Used)
 Total Swap            : 0 MB (0 MB Used)
 System uptime         : 0 days, 0 hour 24 min
 Load average          : 0.28, 0.23, 0.18
 OS                    : Debian GNU/Linux 10
 Arch                  : x86_64 (64 Bit)
 Kernel                : 4.19.0-14-amd64
 TCP CC                : cubic
 Virtualization        : KVM
 Organization          : AS24940 Hetzner Online GmbH
 Location              : Karlsruhe / DE
 Region                : Baden-Württemberg
----------------------------------------------------------------------
 I/O Speed(1st run)    : 695 MB/s
 I/O Speed(2nd run)    : 1.0 GB/s
 I/O Speed(3rd run)    : 806 MB/s
 Average I/O speed     : 841.7 MB/s
----------------------------------------------------------------------
 Node Name        Upload Speed      Download Speed      Latency     
 Speedtest.net    235.31 Mbps       5041.08 Mbps        23.66 ms    
 Shanghai   CT    139.01 Mbps       3197.29 Mbps        211.86 ms   
 Shanghai   CU    1.09 Mbps         1497.48 Mbps        202.30 ms   
 Guangzhou  CT    12.64 Mbps        442.25 Mbps         210.90 ms   
 Shenzhen   CU    525.98 Mbps       1796.63 Mbps        178.78 ms   
 Hongkong   CN    49.60 Mbps        1463.52 Mbps        199.03 ms   
 Singapore  SG    365.11 Mbps       3162.14 Mbps        242.12 ms   
 Tokyo      JP    115.02 Mbps       32.25 Mbps          264.22 ms   
----------------------------------------------------------------------

[Hosthatch]芝加哥VPS测试

上一年黑五上车了他家1c1g10g的芝加哥VPS,他家VPS的特色就是可以组内网,互联不计算流量。另外他家芝加哥的VPS都带40G的ddos防御。

Preparing to unpack .../screen_4.6.2-3+deb10u1_amd64.deb ...
Velocity Online | Tallahassee, FL, US (10G) | 3.40 Gbits/sec  | 951 Mbits/sec
Clouvider       | Los Angeles, CA, US (10G) | 3.41 Gbits/sec  | 952 Mbits/sec
Iveloz Telecom  | Sao Paulo, BR (2G)        | 807 Mbits/sec   | 465 Mbits/sec

iperf3 Network Speed Tests (IPv6):
---------------------------------
Provider        | Location (Link)           | Send Speed      | Recv Speed
                |                           |                 |
Clouvider       | London, UK (10G)          | 1.91 Gbits/sec  | 1.22 Gbits/sec
Online.net      | Paris, FR (10G)           | 1.96 Gbits/sec  | 1.70 Gbits/sec
WorldStream     | The Netherlands (10G)     | 1.66 Gbits/sec  | 871 Mbits/sec
Clouvider       | NYC, NY, US (10G)         | 3.47 Gbits/sec  | 3.68 Gbits/sec
Clouvider       | Los Angeles, CA, US (10G) | 3.42 Gbits/sec  | 2.24 Gbits/sec

Geekbench 5 Benchmark Test:
---------------------------------
Test            | Value                         
                |                               
Single Core     | 602                           
Multi Core      | 584                           
Full Test       | https://browser.geekbench.com/v5/cpu/7342681

root@dragonfsk:~# wget -qO- --no-check-certificate https://raw.githubusercontent.com/oooldking/script/master/superbench.sh | bash
----------------------------------------------------------------------
 Superbench.sh -- https://www.oldking.net/350.html
 Mode  : Standard    Version : 1.1.7
 Usage : wget -qO- sb.oldking.net | bash
----------------------------------------------------------------------
 CPU Model            : Intel(R) Xeon(R) CPU E5-2690 v2 @ 3.00GHz
 CPU Cores            : 1 Cores 2999.998 MHz x86_64
 CPU Cache            : 16384 KB 
 OS                   : Debian GNU/Linux 10 (64 Bit) KVM
 Kernel               : 4.19.0-6-amd64
 Total Space          : 1.7 GB / 9.7 GB 
 Total RAM            : 100 MB / 987 MB (70 MB Buff)
 Total SWAP           : 51 MB / 127 MB
 Uptime               : 28 days 7 hour 41 min
 Load Average         : 0.16, 0.45, 0.35
 TCP CC               : bbr
 ASN & ISP            : AS63473, HostHatch
 Organization         : HostHatch LLC
 Location             : Chicago, United States / US
 Region               : Illinois
----------------------------------------------------------------------
 I/O Speed( 1.0GB )   : 628 MB/s
 I/O Speed( 1.0GB )   : 1.0 GB/s
 I/O Speed( 1.0GB )   : 983 MB/s
 Average I/O Speed    : 878.3 MB/s
----------------------------------------------------------------------
 Node Name        Upload Speed      Download Speed      Latency     
 Speedtest.net    3307.46 Mbit/s    969.34 Mbit/s       3.15 ms     
 Fast.com         0.00 Mbit/s       171.7 Mbit/s        -           
 Nanjing 5G   CT  348.23 Mbit/s     816.77 Mbit/s       253.61 ms   
 Hefei 5G     CT  356.61 Mbit/s     653.23 Mbit/s       230.27 ms   
 Guangzhou 5G CT  1.17 Mbit/s       74.83 Mbit/s        238.42 ms   
 Shanghai 5G  CU  278.34 Mbit/s     669.20 Mbit/s       280.52 ms   
----------------------------------------------------------------------
 Finished in  : 3 min 2 sec
 Timestamp    : 2021-04-09 21:19:21 GMT+8
 Results      : ./superbench.log
----------------------------------------------------------------------
 Share result:
 · https://www.speedtest.net/result/c/c19350d8-b5f9-4126-abc7-5825bac1ce80
 · https://paste.ubuntu.com/p/Rx8T2Zvtnw/
----------------------------------------------------------------------