前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >技术阅读周刊第十二期

技术阅读周刊第十二期

作者头像
crossoverJie
发布2024-01-02 16:29:47
1100
发布2024-01-02 16:29:47
举报
文章被收录于专栏:crossoverJiecrossoverJie

年前最后一篇推送,提前祝大家新年快乐。

Deno vs Go: Native hello world performance | Tech Tonic

URL: https://medium.com/deno-the-complete-reference/deno-vs-go-native-hello-world-performance-c57d8fc13c75

使用 Deno 和 Go 进行基本的接口对比

  • MacBook Pro M2 with 16GB of RAM
  • Deno v1.38.0
  • Go v1.21.3

都是最简单的 httpServer:

代码语言:javascript
复制
Deno.serve({
  port: 3000,
}, (req) => {
  try {
    const pathName = new URL(req.url).pathname;
    if (pathName !== "/") {
      return new Response(null, { status: 404 });
    }
    return new Response("Hello world!");
  } catch (e) {
    return new Response(null, { status: 500 });
  }
});
代码语言:javascript
复制
package main

import (
  "io"
  "net/http"
)

func main() {
  http.HandleFunc("/", helloWorld)
  http.ListenAndServe(":3000", nil)
}

func helloWorld(w http.ResponseWriter, r *http.Request) {
  io.WriteString(w, "Hello world!")
}

image.png

总的来说 Deno 比 Go 慢了 30% 左右,但 CPU 占有率比 Go 更少,Go 的内存占用更低。

这个对比就图一乐。

Top 7 Spring Boot Design Patterns Unveiled | by Dharmendra Awasthi | Dec, 2023 | Stackademic

URL: https://blog.stackademic.com/top-7-spring-boot-design-patterns-unveiled-4a2569f8d324

7 个我们可以学习的 Spring Boot 的设计模式

Singleton Pattern 单例模式

这个没啥好说的,面试都被讲烂了,依然很经典。当我们使用这些注解声明一个 Bean 时@Component, @Service, @Repository, or @Controller,就会被创建一个单例对象注入到 IOC 容器中。

Factory Pattern 工厂模式

Spring 也提供了工厂模式的接口,我们可以自定义创建逻辑:

代码语言:javascript
复制
import org.springframework.beans.factory.FactoryBean;

public class MyFactoryBean implements FactoryBean<MyBean> {
    @Override
    public MyBean getObject() throws Exception {
        // Custom logic to create and return MyBean instance
        return new MyBean();
    }

    @Override
    public Class<?> getObjectType() {
        return MyBean.class;
    }

    @Override
    public boolean isSingleton() {
        return true; // Or false, depending on your bean's scope
    }
}

Builder 创建者模式

这个其实不算是 Spring 所提供的,但确实很好用;通常用于创建需要很多可选参数的对象时使用:

代码语言:javascript
复制
import lombok.Builder;
import lombok.Data;

@Data
@Builder
public class User {
    private String username;
    private String email;
    private int age;
    // Other fields
}

User user = User.builder()
    .username("john_doe")
    .email("john@example.com")
    .age(30)
    .build();

Proxy 代理模式

代理模式在 spring 中通常用于 AOP 切面,可以实现一些通用的非业务逻辑功能;比如日志、缓存、安全检测等:

代码语言:javascript
复制
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;

@Aspect
@Component
public class LoggingAspect {
    
    @Before("execution(* com.example.service.*.*(..))")
    public void beforeServiceMethods() {
        // Logic to be executed before service methods
        System.out.println("Logging before service methods...");
    }
}

Observe 观察者模式

本质上是将业务解耦,生产者发布事件,订阅者接收事件,只是 spring 帮我们封装好了逻辑。

代码语言:javascript
复制
import org.springframework.context.ApplicationEvent;

public class OrderPlacedEvent extends ApplicationEvent {
    private final Order order;

    public OrderPlacedEvent(Object source, Order order) {
        super(source);
        this.order = order;
    }

    // Getters for order information
}


import org.springframework.context.ApplicationEventPublisher;
import org.springframework.stereotype.Service;

@Service
public class OrderService {
    private final ApplicationEventPublisher eventPublisher;

    public OrderService(ApplicationEventPublisher eventPublisher) {
        this.eventPublisher = eventPublisher;
    }

    public void placeOrder(Order order) {
        // Logic to place order

        // Publish OrderPlacedEvent
        eventPublisher.publishEvent(new OrderPlacedEvent(this, order));
    }
}


import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Component;

@Component
public class EmailService {

    @EventListener
    public void sendEmailOnOrderPlacement(OrderPlacedEvent event) {
        Order order = event.getOrder();
        // Logic to send email based on the placed order
    }
}

转转一体化监控系统——Prometheus·Grafana成本治理_TakinTalks稳定性技术交流平台

URL: https://news.shulie.io/?p=8229

链接里有 B 站视频,文字版链接:https://mp.weixin.qq.com/s/FySeVBL7EfihOlNDBvAPpw

转转的监控方案

  • 基于 Prometheus 架构(确实已经是监控领域的标准了)
  • 使用 M3DB 替换了单机的 Prometheus。
    • 我们使用 VM 替换的 Prometheus,转转没有选择 VM 是因为 M3DB 的压缩率更高。
  • 采用 Push 模型推送数据
    • 由于我们使用了 kubernetes,所以是基于 kubernetes 的 SD 实现的服务发现。
    • 所以我们采用的也是 Pull 拉取模型
    • 由 SDK 进行推送,对业务无感知
    • 省略了注册中心,改为了数据库存储服务节点信息。
  • 重写了告警系统,Prometheus 自带的告警系统存在学习难度大等问题。

文章链接:

  • https://medium.com/deno-the-complete-reference/deno-vs-go-native-hello-world-performance-c57d8fc13c75
  • https://blog.stackademic.com/top-7-spring-boot-design-patterns-unveiled-4a2569f8d324
  • https://news.shulie.io/?p=8229
本文参与 腾讯云自媒体同步曝光计划,分享自微信公众号。
原始发表:2023-12-29,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 crossoverJie 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • Deno vs Go: Native hello world performance | Tech Tonic
  • Top 7 Spring Boot Design Patterns Unveiled | by Dharmendra Awasthi | Dec, 2023 | Stackademic
    • Singleton Pattern 单例模式
      • Factory Pattern 工厂模式
        • Builder 创建者模式
          • Proxy 代理模式
            • Observe 观察者模式
            • 转转一体化监控系统——Prometheus·Grafana成本治理_TakinTalks稳定性技术交流平台
            相关产品与服务
            Prometheus 监控服务
            Prometheus 监控服务(TencentCloud Managed Service for Prometheus,TMP)是基于开源 Prometheus 构建的高可用、全托管的服务,与腾讯云容器服务(TKE)高度集成,兼容开源生态丰富多样的应用组件,结合腾讯云可观测平台-告警管理和 Prometheus Alertmanager 能力,为您提供免搭建的高效运维能力,减少开发及运维成本。
            领券
            问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档