Developer Weekly 2

Releasing a high-performance, lightweight, non-blocking and event-loop networking library written in pure Go

Benchmark for implementation of servers that support 1m connections

基于flink和drools的实时日志处理

Kubernetes Handbook——Kubernetes 中文指南/云原生应用架构实践手册

云原生技术有利于各组织在公有云、私有云和混合云等新型动态环境中,构建和运行可弹性扩展的应用。云原生的代表技术包括 容器、服务网格、微服务、不可变基础设施 和 声明式 API。这些技术能够构建容错性好、易于管理和便于观察的松耦合系统。结合可靠的自动化手段,云原生技术使工程师能够轻松地对系统作出频繁和可预测的重大变更。——CNCF(云原生计算基金会)。

Awesome Cloud Native

深入理解JavaScript

101 Tips For Being A Great Programmer (& Human)

When to use the different log levels?

Trace – Only when I would be “tracing” the code and trying to find one part of a function specifically.

Debug – Information that is diagnostically helpful to people more than just developers (IT, sysadmins, etc.).

Info – Generally useful information to log (service start/stop, configuration assumptions, etc). Info I want to always have available but usually don’t care about
under normal circumstances. This is my out-of-the-box config level.

Warn – Anything that can potentially cause application oddities, but for which I am automatically recovering. (Such as switching from a primary to backup server, retrying an operation, missing secondary data, etc.)

Error – Any error which is fatal to the operation, but not the service or application (can’t open a required file, missing data, etc.). These errors will force user (administrator, or direct user) intervention. These are usually reserved (in my apps) for incorrect connection strings, missing services, etc.

Fatal – Any error that is forcing a shutdown of the service or application to prevent data loss (or further data loss). I reserve these only for the most heinous errors and situations where there is guaranteed to have been data corruption or loss.

Developer Weekly 1

架构制图:工具与方法论

软件工程也是工程,因此传统工程制图的一些基本理论,在软件行业同样适用。但另一方面,软件与实体制造业之间还是有着本质区别,所以在制图方面的需求和方式也大相径庭,无法直接套用。作为软件行业的从业者,你可以完全不懂工程制图,但你不得不懂架构制图 —— 这是任何程序员职业生涯的的必修课。

从技术和协议层面来介绍http2

这篇文档会从技术和协议层面来介绍http2。文档起源于2014年4月我在斯德哥尔摩做了一次相关的演讲,在那之后我对演讲内容的细节进行了一些解释和补充,从而写出了这篇文档。
正式版http2规格标准叫做RFC 7540,发布于2015年5月15日:https://www.rfc-editor.org/rfc/rfc7540.txt
如果你有在这篇文章中发现任何我的失误造成的错误或疏漏,请帮我指正。我会在后续版本中修改。
为了让阅读体验更流畅,在这篇文章中我会使用“http2”来指代这一新协议,但请记住该协议的正式名字是HTTP/2。

HTTP/3以及其底层协议QUIC的文档

本书的编撰自2018年3月开始,计划是提供HTTP/3以及其底层协议QUIC的文档,介绍它们的目的、原理、协议细节以及实现等。
本书完全免费,并且是一个协作项目,欢迎所有愿意帮忙的人前来协助!

无锁编程

A collection of resources on wait-free and lock-free programming.

Go race detector

race_detector

线上程序发现处理速度变慢,内存占用变大,后面排查发现 build的时候指定了-race 参数,导致处理速度和内存变大。
正确使用方法是:在运行测试的时候指定-race,来检查是否存在并发写的情况。不能用于线上程序。

官方文档:

The cost of race detection varies by program, but for a typical program, memory usage may increase by 5-10x and execution time by 2-20x.

The race detector currently allocates an extra 8 bytes per defer and recover statement. Those extra allocations are not recovered until the goroutine exits. This means that if you have a long-running goroutine that is periodically issuing defer and recover calls, the program memory usage may grow without bound. These memory allocations will not show up in the output of runtime.ReadMemStats or runtime/pprof.

参考链接

Golang: Concurrency is Hard; So What Can We Do About It?
SRE: Debugging: Simple Memory Leaks in Go
Does the Go race detector catch all data race bugs?
Race-free doesn’t mean deterministic

final vs static final in java

For final, it can be assigned different values at runtime when initialized. For example

Class Test{
  public final int a;
}
Test t1  = new Test();
t1.a = 10;
Test t2  = new Test();
t2.a = 20; //fixed

Thus each instance has different value of field a.

For static final, all instances share the same value, and can’t be altered after first initialized.

Class TestStatic{
      public static final int a;
}
Test t1  = new Test();
t1.a = 10;
Test t2  = new Test();
t1.a = 20;   // ERROR, CAN'T BE ALTERED AFTER THE FIRST INITIALIZATION.

private final static attribute vs private final attribute
Static vs Instance Variables: Difference?

Spring RestTemplate 消息转换2种使用方式

拦截器

public class MyXmlInterceptor implements ClientHttpRequestInterceptor {

@Override
public ClientHttpResponse intercept(HttpRequest request, byte[] body, ClientHttpRequestExecution execution) throws IOException {
    ClientHttpResponse response = execution.execute(request, body);
    HttpHeaders headers = response.getHeaders();

    // you'd want to check if the value needs to be changed
    if (headers.containsKey("Content-Type")) {
        headers.remove("Content-Type");
    }

    headers.add("Content-Type", "application/xml");

    return response;
}
RestTemplate t = new RestTemplate();
t.getInterceptors().add(new MyXmlInterceptor());

自定义

RestTemplate restTemplate = new RestTemplate();
List<HttpMessageConverter<?>> messageConverters = new ArrayList<HttpMessageConverter<?>>();
Jaxb2RootElementHttpMessageConverter jaxbMessageConverter = new Jaxb2RootElementHttpMessageConverter();
List<MediaType> mediaTypes = new ArrayList<MediaType>();
mediaTypes.add(MediaType.TEXT_HTML);
jaxbMessageConverter.setSupportedMediaTypes(mediaTypes);
messageConverters.add(jaxbMessageConverter);
restTemplate.setMessageConverters(messageConverters);