1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 package main import ( "context" "fmt" "os" "os/signal" "syscall" "time" ) type Result struct { Hit string Err error } //// Search runs query on a backend and returns the result. //type Search func(query string) Result // //// First runs query on replicas and returns the first result. //func First(query string, replicas ...Search) Result { // c := make(chan Result, len(replicas)) // search := func(replica Search) { c <- replica(query) } // for _, replica := range replicas { // go search(replica) // } // return <-c //} // Search runs query on a backend and returns the result.……
……
gRPC是Google开源的RPC框架,具有以下的优点:
提供高效的进程间通信。gRPC没有使用XML或者Json的文本格式,而是采用基于protocol buffers的二进制协议;同时使用HTTP/2作为通信协议,从而能快速的处理进程间通信。 简单且良好的服务接口和模式。契约优先,先定义接口,再实现细节。 支持多语言 再介绍下RPC: RPC:Remote Procedure Call 远程过程调用,简单的理解是一个节点请求另一个节点的服务。与远程过程调用相对的就是本地过程调用,通过函数指针进行实现。那远程过程调用如何通知远程机器要调用这个方法呢?
// Client端 // Student student = Call(ServerAddr, addAge, student) 1. 将这个调用映射为Call ID。 2. 将Call ID,student(params)序列化,以二进制形式打包 3. 把2中得到的数据包发送给ServerAddr,这需要使用网络传输层 4. 等待服务器返回结果 5. 如果服务器调用成功,那么就将结果反序列化,并赋给student,年龄更新 // Server端 1. 在本地维护一个Call ID到函数指针的映射call_id_map,可以用Map<String, Method> callIdMap 2. 等待客户端请求 3. 得到一个请求后,将其数据包反序列化,得到Call ID 4. 通过在callIdMap中查找,得到相应的函数指针 5. 将student(params)反序列化后,在本地调用addAge()函数,得到结果 6. 将student结果序列化后通过网络返回给Client gRPC包含四种基础的通信模式:
一元模式 服务器端流RPC 客户端流RPC 双向流RPC Etcd
https://mp.weixin.qq.com/mp/appmsgalbum?action=getalbum&album_id=1574539663539781634&__biz=MzUzNTY5MzU2MA==#wechat_redirect……
linux 查问题 yum install nmon top pref top us: user cpu time (or) % CPU time spent in user space sy: system cpu time (or) % CPU time spent in kernel space ni: user nice cpu time (or) % CPU time spent on low priority processes id: idle cpu time (or) % CPU time spent idle wa: io wait cpu time (or) % CPU time spent in wait (on disk) hi: hardware irq (or) % CPU time spent servicing/handling hardware interrupts si: software irq (or) % CPU time spent servicing/handling software interrupts st: steal time - - % CPU time in involuntary wait by virtual cpu while hypervisor is servicing another processor (or) % CPU time stolen from a virtual machine si不均衡:网卡多队列/ DPDK……
https://razeencheng.com/post/go-swagger.html……
Head-of-line blocking……
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 package main /* 二叉搜索树 右子树所有节点均大于根节点, 左子树所有节点均小于根节点 而且左右子树需要均为二叉搜索树 */ type searchTreeNode struct { data int left *searchTreeNode right *searchTreeNode } func DeleteNode(root *searchTreeNode, value int) *searchTreeNode { if root == nil { return nil } // 待删除节点在右子树 if root.data < value { root.right = DeleteNode(root.right, value) return root } // 待删除节点在左子树 if root.data > value { root.left = DeleteNode(root.left, value) return root } // 待删除节点为根节点 // 找到右子树的最小值和根节点交换 // 在删除掉交换后的那个节点 if root.……
分布式事务相当于本地事务加上消息传递。先扣钱再加钱。牺牲了延迟性,保障数据最终一致。
消息的可靠存储:
Transactional outbox 本地一个数据库通过事务保障 begin transaction
polling publiser 去拉mysql中的记录从而通过消息队列发送 改用canal订阅binlog再发送到mq。 消息的重复消费,使用幂等处理来解
版本号来解决 全局唯一ID加去重表
2PC二阶段提交
存在事务协调者和事务参与者 ……
LHV Connect Live base url is: https://connect.lhv.eu/
Sandbox base url is: https://connect.prelive.lhv.eu/
To start using LHV Connect services you need:
Valid customer agreement with LHV Sign an additional Connect agreement Connection certificates The general approach and on-boarding steps, before you can start using the API in Live environment:
contact the LHV Connect support team at **connect@lhv.ee** or your client relationship manager define the services you expect to use and consult our team when needed support team prepares your dedicated Sandbox test environment. We expect it to be similar to your future setup in Live - the list of used services, account setup and other details. support team sends you connection certificates for the test environment (not shared with live) and additional instructions development and testing of your integrations can start! when you are confident are ready to proceed to Live inform the support team and relationship manager relationship manager prepares and signs the Connect agreement support team sends you instruction for connection certificate generation (more details below) Live usage can start!……
《数据库系统实现》
存储方式:
内存存储 磁盘存储 存在的问题:
浪费存储空间,只看一部分,却要把全部加载到内存 读写查不够高效 不能应对意外情况 数据库系统可以解决以上的问题
block,file,Directory
block:扇区的逻辑集合,一般8K
file:一系列的块组成,块信息被存储在Directory Entry中
目录被存储在少数几个block中
加速磁盘操作:
- 顺序写入,LSM tree - 预加载 ……