编程语言:Go
Golang 中 map 探究
本文主要通过探究在golang 中map的数据结构及源码实现来学习和了解map的特性,共包含map的模型探究、存取、扩容等内容。
Go 生态下的字节跳动大规模微服务性能优化实践
Go 是一门很有特色的编程语言,已经被广泛应用到不少领域,随着使用场景的发展,一些性能相关的问题也开始逐渐暴露出来。本次分享将以字节跳动的性能优化工作为例,介绍基于 Go 生态的微服务体系下,分析系统性能、优化不同层次软件以提升运行性能、提高资源使用效率的一些实践和经验,会特别介绍在 Go 语言 SDK 侧的一些优化工作。
Go语言DDD实战初级篇-限界上下文
DDD分为战略设计和战术设计,战略设计就是划分子域和限界上下文的过程。领域划分为子域的通用划分形式是把领域划分为 核心子域、支撑子域、通用子域。我们在落地过程中常常会很容易划分出核心子域,一般设计mvp的时候mvp就是核心子域。但是领域划分出核心子域、支撑子域和通用子域之后就算划分完成了吗?
Go 1.18 的那些事——工作区、模糊测试、泛型
2022 年 3 月 15 日,Google 发布了万众瞩目的 Golang 1.18,带来了好几个重大的新特性,包括:
- 解决本地同时开发多个仓库带来的一些问题的工作区(Workspace)
- 能够自动探测代码分支,随机生成输入,并且检查代码是否会 panic 的模糊测试(Fuzzing Test)
- 众多开发者盼星星盼月亮终于等到的泛型支持。
本文将简单讲述这三个特性的相关内容。
Strategy Letter III: Let Me Go Back!
When you’re trying to get people to switch from a competitor to your product, you need to understand barriers to entry, and you need to understand them a lot better than you think, or people won’t switch and you’ll be waiting tables.
IOC-golang 的 AOP 原理与应用
AOP (面向切面编程)是一种编程设计思想,旨在通过拦截业务过程的切面,实现特定模块化的能力,降低业务逻辑之间的耦合度。
How We Halved Go Monorepo CI Build Time
Before 2021, Uber engineers would have to take quite a taxing journey to make a code change to the Go Monorepo. First, the engineer would make their changes on a local branch and put up a code revision to our internal code review system, Phabricator. Next, our infrastructure would see the request and initiate a number of validation jobs on our CI. Those jobs would run build and test validation using the Bazel™ build system, check the coverage, do some other work, and report back to the user a red light (i.e., tests failed or some other issues) or green light. Next, the user, after seeing the “green light,” would get their code reviewed and then initiate a “land” request to the Submit Queue. The queue, after receiving their request, would patch their changes on the latest HEAD of the main branch and re-run these associated builds and tests to make sure their change would be valid at the current state of the repository. If everything looked good, the changes would be pushed and the revision would be closed.
This sounds pretty easy, right? Make sure everything is green, reviewed, and then let the queue do the work to push your change!
Well… what if the change is to a fundamental and widely used library? All packages depending on the library will need to be validated, even though the change itself is only a few lines of code. This might slow down the “build and test” part. Validating this change could sometimes take several hours. Internally, we call such changes big changes.
Go 语言使用 MySQL 的常见故障分析和应对方法
很多同学在使用Go和数据库打交道的过程中,经常会遇到一些异常不知道为什么,本文从SQL连接池的原理进行分析,模拟了一些例子对异常的现象进行解读分析,并给出一些常见的应对手段,期望能帮助到大家。
字节跳动开源 Go HTTP 框架 Hertz 设计实践
Hertz 是字节跳动服务框架团队研发的超大规模的企业级微服务 HTTP 框架,具有高易用性、易扩展、低时延等特点。在经过了字节跳动内部一年多的使用和迭代,如今已在 CloudWeGo 正式开源。目前,Hertz 已经成为了字节跳动内部最大的 HTTP 框架,线上接入的服务数量超过 1 万,峰值 QPS 超过 4 千万。除了各个业务线的同学使用外,也服务于内部很多基础组件,如:函数计算平台 FaaS、压测平台、各类网关、Service Mesh 控制面等,均收到不错的使用反馈。在如此大规模的场景下,Hertz 拥有极强的稳定性和性能,在内部实践中某些典型服务,如框架占比较高的服务、网关等服务,迁移 Hertz 后相比 Gin 框架,资源使用显著减少,CPU 使用率随流量大小降低 30%-60%,时延也有明显降低。
Hertz 坚持内外维护一套代码,为开源使用提供了强有力的保障。通过开源, Hertz 也将丰富云原生的 Golang 中间件体系,完善 CloudWeGo 生态矩阵,为更多开发者和企业搭建云原生化的大规模分布式系统,提供一种现代的、资源高效的的技术方案。
通过 Goyacc 构建 Elasticsearch Querystring 解析器 - 领域特定语言语法分析实践
领域特定语言(DSL),如 SQL、Elasticsearch Querystring 等,往往是为专门的目的设计的。在特定的任务中,DSL 通过在表达能力上做的妥协换取在某一领域内的高效。
在飞书套件日志系统的私有化研发过程中,为了符合研发同学查询日志的习惯,尝试使用 Elasticquery Querystring(下简称为 Querystring)作为过滤器的查询条件语句,由此需要可用的 Golang Querystring 解析器。由于目前开源界无法找到完善的实现,尝试使用 Goyacc 自行构建。
Data Race Patterns in Go
Uber has adopted Golang (Go for short) as a primary programming language for developing microservices. Our Go monorepo consists of about 50 million lines of code (and growing) and contains approximately 2,100 unique Go services (and growing).
Go makes concurrency a first-class citizen; prefixing function calls with the go keyword runs the call asynchronously. These asynchronous function calls in Go are called goroutines. Developers hide latency (e.g., IO or RPC calls to other services) by creating goroutines. Two or more goroutines can communicate data either via message passing (channels) or shared memory. Shared memory happens to be the most commonly used means of data communication in Go.
Golang 常见设计模式之单例模式
之前我们已经看过了 Golang 常见设计模式中的装饰和选项模式,今天要看的是 Golang 设计模式里最简单的单例模式。单例模式的作用是确保无论对象被实例化多少次,全局都只有一个实例存在。根据这一特性,我们可以将其应用到全局唯一性配置、数据库连接对象、文件访问对象等。Go 语言实现单例模式的方法有很多种,下面我们就一起来看一下。
Go语言项目实践及新特性解读
近几年之家基于Go在不同的业务场景下(高并发服务、云原生、中间件、机器学习、用户产品、嵌入式等)有着丰富的开发实践,接下来会基于这些场景分享一些典型案例。
Dynamic Data Race Detection in Go Code
Uber has extensively adopted Go as a primary programming language for developing microservices. Our Go monorepo consists of about 50 million lines of code and contains approximately 2,100 unique Go services. Go makes concurrency a first-class citizen; prefixing function calls with the go keyword runs the call asynchronously. These asynchronous function calls in Go are called goroutines. Developers hide latency (e.g., IO or RPC calls to other services) by creating goroutines within a single running Go program. Goroutines are considered “lightweight”, and the Go runtime context switches them on the operating-system (OS) threads. Go programmers often use goroutines liberally. Two or more goroutines can communicate data either via message passing (channels) or shared memory. Shared memory happens to be the most commonly used means of data communication in Go.
A data race occurs in Go when two or more goroutines access the same memory location, at least one of them is a write, and there is no ordering between them, as defined by the Go memory model. Outages caused by data races in Go programs are a recurring and painful problem in our microservices. These issues have brought down our critical, customer-facing services for hours in total, causing inconvenience to our customers and impacting our revenue. In this blog, we discuss deploying Go’s default dynamic race detector to continuously detect data races in our Go development environment. This deployment has enabled detection of more than 2,000 races resulting in ~1,000 data races fixed by more than two hundred engineers.
打造 Go 语言最快的排序算法
说到排序算法,很多同学会想起快速排序、堆排序、冒泡排序这些耳熟能详的算法。了解得深一些的同学,也可能看过例如 Python 的 timsort 以及 C++ intro sort 之类的排序算法。
但是我们也会有很多疑问,例如 Go 语言中使用的快速排序和我们书上学到的快速排序有什么区别呢?如果我们自己写一个快排,会比 Go 语言自带的快吗?排序算法方面业界最新的进展是什么呢,有没有一个算法是最快的?
Golang在商业化广告的优化实践
ssp和adx系统是广告系统中qps最高,io密集度最高的系统,承担着广告大部分收入的同时,对latency不能响应太慢。通过pprof性能调优工具分析系统资源消耗,进行优化实践,性能得到大幅提高,顺利渡过双十一、双十二等大促活动。