分类 工作&技术 下的文章

CPU极其拉跨,也不排除是运行YABS高占用后自动限制了
其它都还可以。其实往往最不重要的就是CPU,运算能力过剩,所以,用起来感觉还好了。


# ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## #
#              Yet-Another-Bench-Script              #
#                     v2024-03-05                    #
# https://github.com/masonr/yet-another-bench-script #
# ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## #

Sun Mar 24 12:39:03 AM +08 2024

Basic System Information:
---------------------------------
Uptime     : 2 days, 10 hours, 15 minutes
Processor  : QEMU Virtual CPU version 2.5+
CPU cores  : 4 @ 2294.576 MHz
AES-NI     : ✔ Enabled
VM-x/AMD-V : ❌ Disabled
RAM        : 3.8 GiB
Swap       : 0.0 KiB
Disk       : 118.0 GiB
Distro     : Debian GNU/Linux 12 (bookworm)
Kernel     : 6.1.0-18-amd64
VM Type    : KVM
IPv4/IPv6  : ✔ Online / ❌ Offline

IPv4 Network Information:
---------------------------------
ISP        : netcup GmbH
ASN        : AS197540 netcup GmbH
Host       : netcup GmbH
Location   : Nuremberg, Bavaria (BY)
Country    : Germany

fio Disk Speed Tests (Mixed R/W 50/50) (Partition /dev/vda3):
---------------------------------
Block Size | 4k            (IOPS) | 64k           (IOPS)
  ------   | ---            ----  | ----           ----
Read       | 74.15 MB/s   (18.5k) | 1.24 GB/s    (19.4k)
Write      | 74.34 MB/s   (18.5k) | 1.25 GB/s    (19.5k)
Total      | 148.50 MB/s  (37.1k) | 2.49 GB/s    (39.0k)
           |                      |
Block Size | 512k          (IOPS) | 1m            (IOPS)
  ------   | ---            ----  | ----           ----
Read       | 1.67 GB/s     (3.2k) | 1.98 GB/s     (1.9k)
Write      | 1.76 GB/s     (3.4k) | 2.11 GB/s     (2.0k)
Total      | 3.44 GB/s     (6.7k) | 4.09 GB/s     (3.9k)

iperf3 Network Speed Tests (IPv4):
---------------------------------
Provider        | Location (Link)           | Send Speed      | Recv Speed      | Ping
-----           | -----                     | ----            | ----            | ----
Clouvider       | London, UK (10G)          | 1.08 Gbits/sec  | 928 Mbits/sec   | 22.6 ms
Eranium         | Amsterdam, NL (10G)       | 1.08 Gbits/sec  | 938 Mbits/sec   | 11.0 ms
Telia           | Helsinki, FI (10G)        | 1.07 Gbits/sec  | 935 Mbits/sec   | 32.2 ms
Uztelecom       | Tashkent, UZ (10G)        | 397 Mbits/sec   | 746 Mbits/sec   | 107 ms
Leaseweb        | Singapore, SG (10G)       | 831 Mbits/sec   | 733 Mbits/sec   | 257 ms
Clouvider       | Los Angeles, CA, US (10G) | 966 Mbits/sec   | 326 Mbits/sec   | 148 ms
Leaseweb        | NYC, NY, US (10G)         | 1.01 Gbits/sec  | 711 Mbits/sec   | 91.9 ms
Edgoo           | Sao Paulo, BR (1G)        | 908 Mbits/sec   | 202 Mbits/sec   | 178 ms

Running GB6 benchmark test... *cue elevator music*
Geekbench 6 Benchmark Test:
---------------------------------
Test            | Value
                |
Single Core     | 416
Multi Core      | 875
Full Test       | https://browser.geekbench.com/v6/cpu/5436597

一直在犯这个错误,一直还是要继续犯。
select sum(xxx) where xxx,如果where不存在,返回null,而不是0
象是select count(xxx) where xxx,就会老老实实返回0。不知道为什么mysql有这么个奇怪的设定。
这段代码,如果在shop_stock里面找不到指定的shop_id的记录,那么,由于是null,它不能放在int里,后面的adata.Stock将维持上一次查询时的值,而不是预期中的0。

var adata stockstruct
for rows.Next() {
rows.Scan(&adata.Id, &adata.Name)
sql = "select sum(stock) from shop_stock where shopid=?"
dao.DB.Get(&adata.Stock, sql, adata.Id)
.....
}

花5分钟码完代码,收工睡觉。

modify0322.jpg

    time1, _ := strconv.Atoi(c.PostForm("time1"))
    time2, _ := strconv.Atoi(c.PostForm("time2"))
    shopid, _ := strconv.Atoi(c.PostForm("shopid"))
    if (time1 == 0 && time2 != 0) || (time1 != 0 && time2 == 0) {
        reply.Response(500, "时间参数错误")
        return
    }
    if time1 != 0 {
        extracond += " and o.time>=? and o.time<=?"
        args = append(args, time1, time2)
    }
    if shopid != 0 {
        extracond += " and sd.shopid=?"
        args = append(args, shopid)
    }

先前的版本在处理休眠时有点问题,这个版本修正了
因为正好需要24的机器,所以晚上抢了一把,很成功。注意截图时间。 :)

grabali.jpg

/*
https://help.aliyun.com/zh/ram/user-guide/create-an-accesskey-pair 获得主帐号的AccessKey ID AccessKey Secret
确保有不少于24块的余额
*/

package main

import (
        "fmt"
        "os"
        "time"

        openapi "github.com/alibabacloud-go/darabonba-openapi/v2/client"
        swas_open20200601 "github.com/alibabacloud-go/swas-open-20200601/client"
        "github.com/alibabacloud-go/tea/tea"
)

func CreateClient(Key, Secret string) (_result *swas_open20200601.Client, _err error) {
        config := &openapi.Config{
                AccessKeyId:     tea.String(Key),
                AccessKeySecret: tea.String(Secret),
        }
        config.Endpoint = tea.String("swas.cn-hongkong.aliyuncs.com")
        _result = &swas_open20200601.Client{}
        _result, _err = swas_open20200601.NewClient(config)
        return _result, _err
}

func SDKCreate(Key, Secret string) error {
        client, err := CreateClient(Key, Secret)
        if err != nil {
                return err
        }
        request := &swas_open20200601.CreateInstancesRequest{
                RegionId: tea.String("cn-hongkong"),                      //香港
                ImageId:  tea.String("8b798eb927684a08b26bb95da94f5812"), //debian11
                PlanId:   tea.String("swas.s2.c2m1s40b30t1.un"),          //轻量24
                Period:   tea.Int32(1),
        }
        _, err = client.CreateInstances(request)
        if err != nil {
                return err
        }
        return nil
}

func main() {
        location, err := time.LoadLocation("Asia/Shanghai")
        if err != nil {
                fmt.Println("Error loading location:", err)
                return
        }
        time.Local=location
        args := os.Args
        if len(args) < 3 {
                fmt.Printf("Usage: %s <AccessKeyId> <AccessKeySecret>\n", args[0])
                return
        }

        now := time.Now()
        tomorrowMidnight := time.Date(now.Year(), now.Month(), now.Day()+1, 0, 0, 0, 0, time.Local)

        if now.Hour() != 0 {
                fmt.Println("Waiting for 00:00:00 to start...")
                sleepDuration := tomorrowMidnight.Sub(now)
                time.Sleep(sleepDuration)
        }

        //因为阿里可能不整点放货,所以,这里不再连续抢了,因为SDK的限制是10次/分钟
        //现在改为每分钟抢10次左右,一直抢5分钟。 也就是6秒左右抢一次。按照中位数,3秒,应该还是希望很大。
        for i := 1; i <= 50; i++ {
                err := SDKCreate(args[1], args[2])
                if err != nil {
                        fmt.Printf("%d - Error: %s\n", i, err)
                } else {
                        fmt.Printf("%d - Success! Please check it in your aliyun console.\n", i)
                        break
                }
                time.Sleep(6 * time.Second)
        }

        fmt.Println("Done")
}

昨晚一台低频使用的测试服务器进行了一次向内部服务器发起的api请求,结果被雷池拦截了。这个操作是一个不允许出错、正常也不会出错的操作,程序对出错的机制是一直重试直到成功。这就死循环了,一直到早上发现后手工处理。
这个锅雷池不背,是我们把测试服务器忘记设在白名单中。然而,这次事故暴露出雷池的一个大问题,有点象反射放大攻击,测试服务器向雷池发一个几十字节的HTTP请求包,雷池就返回一个大得多的拦截出错页,几十上百倍的放大,准确数据我懒得看了。而且这个出错页是不可修改的。
我这是腾讯云的按量计费,0.8元/G啊!真有人攻击,那不分分钟第二天起来房子不见了? 还好我有先见之明,我是把API服务器的闲时最大带宽设置成的3M,攻击就攻击,跑满就跑满吧,否则,今早就该提桶跑路了。
成事不足,败事有余。把雷池撤了算了。

图片_20240319154731.png

图片_20240319154743.png