编程笔记

lifelong learning & practice makes perfect

系统依赖

  • Jenkins
  • nginx
  • golang后端
  • 前端

问题

  1. 接口调用失败,到服务器上本地请求接口失败
  2. 通过ps搜索后端进程,发现服务进程不存在,判定=>Jenkins构建失败
  3. 然后到Jenkins上查看构建日志,发现报错信息,’sudo stop xxxx [no runing]’,错误判定为有人修改了服务器配置,问了一圈人,没有修改
  4. 排除员工原因,查找代码原因,尝试直接执行在服务器本地的后端可执行程序,报错
  5. 排查代码原因

反思

大部分错误最先从代码层面开始找,比较有效率,服务器配置之类的改动毕竟比较少;错误日志需要仔细查看,往往兜兜转转找了一圈会发现
错误提示一开始就清晰地摆在面前.
下决定前多思考.

command

  1. lsb_release : 查看LSB(Linux Standard Base),Distribution information

description & usage

  1. LSB (Linux Standard Base)
  2. tldr description
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    lsb_release

    Provides certain LSB (Linux Standard Base) and distribution-specific information.

    - Print all available information:
    lsb_release -a

    - Print a description (usually the full name) of the operating system:
    lsb_release -d

    - Print only the operating system name (ID), suppressing the field name:
    lsb_release -i -s

    - Print the release number and codename of the distribution, suppressing the field names:
    lsb_release -rcs

    example

    1
    2
    3
    4
    5
    LSB Version:    :core-4.1-amd64:core-4.1-noarch
    Distributor ID: CentOS
    Description: CentOS Linux release 8.2.2004 (Core)
    Release: 8.2.2004
    Codename: Core

Waht

slow_log table

  1. table

    column type null default description
    start_time timestamp(6) NO CURRENT_TIMESTAMP(6) Time the query began.
    user_host mediumtext NO NULL User and host combination.
    query_time time(6) NO NULL Total time the query took to execute.
    lock_time time(6) NO NULL Total time the query was locked.
    rows_sent int(11) NO NULL Number of rows sent.
    rows_examined int(11) NO NULL Number of rows examined.
    db varchar(512) NO NULL Default database.
    last_insert_id int(11) NO NULL last_insert_id.
    insert_id int(11) NO NULL Insert id.
    server_id int(10) unsigned NO NULL The server’s id.
    sql_text mediumtext NO NULL Full query.
    thread_id bigint(21) unsigned NO NULL Thread id.
    rows_affected int(11) NO NULL Number of rows affected by an UPDATE or DELETE (from MariaDB 10.1.2)
  2. reference

  1. 查看相关参数
    1
    2
    show variables like 'long%';
    show variables like 'slow%';
    • long_query_time,SQL语句执行时间超过此数值,记录日志
    • slow_query_log,是否开启慢查询(ON/OFF)
    • slow_query_log_file,慢查询日志文件
    • slow_launch_time
    • log_output,慢查询日志输出方式,可选FILE(文件,通过slow_query_log_file查询),TABLE(数据表是mysql.slow_log表)
  2. 设置参数
    1
    set long_query_time=0.5;
    开启慢查询日志,需要设置如下参数:
    • long_query_time,慢查询时间
    • slow_query_log,是否开启
    • log_output,日志输出方式,这个是全局变量.
      通过set global设置,如:
      1
      2
      3
      SET GLOBAl log_output='TABLE';

      SET GLOBAl log_output='FILE';
  3. 通过sql查询
    1
    select * from mysql.slow_log;
  4. 通过文件查询
    查询slow_query_log_file参数得到慢查询日志文件所在位置,查看文件.

Solution 性能优化

索引

在无索引的表中查询会进行全表扫描,如果表的数据量很大,则扫描大量的数据,执行效率过
慢,占用数据库连接,连接数堆积很快达到数据库的最大连接数设置,新的应用请求将会被拒绝导致故障发生。
隐式转换也会导致索引无法使用.

创建索引
  1. 在经常查询而不经常增删改操作的字段加索引。
  2. order by与group by后应直接使用字段,而且字段应该是索引字段。
  3. 一个表上的索引不应该超过6个。
  4. 索引字段的长度固定,且长度较短。
  5. 索引字段重复不能过多。
  6. 在过滤性高的字段上加索引。
使用索引注意事项
  1. 使用like关键字时,前置%会导致索引失效。
  2. 使用null值会被自动从索引中排除,索引一般不会建立在有空值的列上。
  3. 使用or关键字时,or左右字段如果存在一个没有索引,有索引字段也会失效。
  4. 使用!=操作符时,将放弃使用索引。因为范围不确定,使用索引效率不高,会被引擎自动改为全表扫描。
  5. 不要在索引字段进行运算。
  6. 在使用复合索引时,最左前缀原则,查询时必须使用索引的第一个字段,否则索引失效;并且应尽量让字段顺序与索引顺序一致。
  7. 避免隐式转换,定义的数据类型与传入的数据类型保持一致。
验证

使用mysql的explain分析sql,查看执行计划.

  1. 执行计划参数含义
  2. 例如一个sql执行计划如下:
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
      // type为ALL,是全表扫描,每次执行需要扫描505560行数据
    id: 1
    select_type: SIMPLE
    table: customers
    type: ALL
    possible_keys: NULL
    key: NULL
    key_len: NULL
    ref: NULL
    rows: 505560
    Extra: Using where
    增加索引后:
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
      // 执行计划看到type为ref,基于索引的等值查询,或者表间等值连接
    id: 1
    select_type: SIMPLE
    table: customers
    type: ref
    possible_keys: idx_cus
    key: idx_cus
    key_len: 31
    ref: const
    rows: 4555
    Extra: Using index condition

    参考

  3. 阿里云: https://help.aliyun.com/document_detail/52274.html?spm=a2c4g.11186623.2.8.1b1945135Wahhf

通过iperf,iperf3测试网络

iperf用法

tldr工具获取的iperf用法如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
iperf

Measure network bandwidth between computers.
More information: https://iperf.fr.
- Run on server:
iperf -s

- Run on server using UDP mode and set server port to listen on 5001:
iperf -u -s -p 5001

- Run on client:
iperf -c server_address

- Run on client every 2 seconds:
iperf -c server_address -i 2

- Run on client with 5 parallel threads:
iperf -c server_address -P 5

- Run on client using UDP mode:
iperf -u -c server_address -p 5001

分别启动server和client进行测试,如:

1
2
iperf -s -p 9988 -f M
iperf -c 111.111.111.111 -p 9988 -t 300 -d -f M -i 2

参数说明

  1. -f 格式/单位:Kbits, Mbits, KBytes, MBytes
  2. -i
  3. -p
  4. -P
  5. -u
  6. -c
  7. -s

在阿里云服务器上遇到的问题

  1. 问题
    阿里云服务器上仅开放了80和443,及ssh端口,其他端口未开放,不能使用其他端口进行测试,也无权限开放新的端口用
    于测试,服务上提供api接口的服务也都是通过nginx反向代理实现.
  2. 测试代码
1
2
3
4
5
6
7
8
9
address, err := net.ResolveTCPAddr("tcp", "http://server_address:18090")
if err != nil {
fmt.Println(err)
}
conn, err := net.DialTCP("tcp4", nil, address)
if err != nil {
fmt.Println(err)
}
conn.Write([]byte("test connect"))

无法建立tcp连接,timeout

解决

服务器上无可用端口用于测试,仅开放的80,443等端口已被网页服务服务占用,可以通过ssh端口转发到一个未暴露的端口,在该端口启动iperf的服务端进行测试.

1
2
3
4
ssh -L local_port:localhost:server_port_for_iperf -N -T user@server_address -p   server_ssh_port
如:
ssh -L 9999:localhost:8888 -N -T user_test@111.111.111.111 -p 22
将发送到本地端口9999的请求数据转发到111.111.111.111转发到8888端口

在服务器上启动iperf server

1
2
3
4
iperf -s -p port -f M

iperf -s -p 8888
使用TCP方式,在8888端口启动服务端,监听

结果

数据

1
2
3
4
5
6
7
8
9
10
11
12
[ ID] Interval       Transfer     Bandwidth
[ 13] 0.0-44.1 sec 30.5 MBytes 0.69 MBytes/sec
[ 7] 0.0-44.2 sec 30.6 MBytes 0.69 MBytes/sec
[ 9] 0.0-44.2 sec 30.6 MBytes 0.69 MBytes/sec
[ 11] 0.0-44.2 sec 30.6 MBytes 0.69 MBytes/sec
[ 15] 0.0-44.2 sec 30.6 MBytes 0.69 MBytes/sec
[ 21] 0.0-44.9 sec 31.6 MBytes 0.70 MBytes/sec
[ 17] 0.0-45.1 sec 31.9 MBytes 0.71 MBytes/sec
[ 4] 0.0-45.2 sec 32.5 MBytes 0.72 MBytes/sec
[ 18] 0.0-45.2 sec 32.1 MBytes 0.71 MBytes/sec
[ 5] 0.0-45.2 sec 32.5 MBytes 0.72 MBytes/sec
[SUM] 0.0-45.2 sec 314 MBytes 6.94 MBytes/sec

分析

参考

  1. ssh端口转发: 玩转SSH端口转发 https://zhuanlan.zhihu.com/p/26547381
  2. nginx反向代理:

3.

外观配置

resource position

C:\Users(user_name)\AppData\Local\Packages\Microsoft.WindowsTerminal_8wekyb3d8bbwe\RoamingState

icon

每个profile可单独设置,增加icon项指定icon位置

1
"icon" : "ms-appdata:///roaming/ubuntu.png"

background

1
"backgroundImage": "ms-appdata:///roaming/arch_linux.jpg",

  • Errror description

MFC dll中的界面在Debug时调用UpdateData()函数,会判断窗口的运行环境是否跨线程,如果创建窗口的线程与调用该函数的线程不是同一个,就会触发CWnd的AssertVaild()函数中断.提示:

it is likely that you have passed a C++ object from one thread to another and have used that object in a way that was not intended.把一个C++对象从一个线程传到另一个线程,使用对象的方式不正确(与代码的原本设计相悖)

阅读全文 »

What is it

图像风格迁移,可以生成特定风格的图像,例如由下面的图像Content生成图像Genrated Image G。

StyleTransfer

阅读全文 »

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
//修不完的bug
class CBase
{
public:
virtual bool Func(unsigned int num,double dNum,vector<bool>& status){return false;};
protected:

private:

}
class CDerive
{
public:
bool Func(unsigned int num,double dNum){return true;};
protected:

private:

}
int main(){
CBase *pBase=new CDerive();
std::cout<<pBase->Func()<<std::endl;
}
阅读全文 »

隐私权条款

非常欢迎您光临 programnotes.cn(以下简称本网站),为了让您能够安心使用本网站的各项服务与资讯,特此向您说明本网站的隐私权保护政策,以保障您的权益,请您详阅下列内容:

一、隐私权保护政策的适用范围

隐私权保护政策内容,包括本网站如何处理在您使用网站服务时收集到的个人识别资料。隐私权保护政策不适用于本网站以外的相关连结网站,也不适用于非本网站所委託或参与管理的人员。

二、个人资料的蒐集、处理及利用方式

  • 当您造访本网站或使用本网站所提供之功能服务时,我们将视该服务功能性质,请您提供必要的个人资料,并在该特定目的范围内处理及利用您的个人资料;非经您书面同意,本网站不会将个人资料用于其他用途。
  • 本网站在您使用服务信箱、问卷调查等互动性功能时,会保留您所提供的姓名、电子邮件地址、联络方式及使用时间等。
  • 于一般浏览时,伺服器会自行记录相关行径,包括您使用连线设备的IP位址、使用时间、使用的浏览器、浏览及点选资料记录等,做为我们增进网站服务的参考依据,此记录为内部应用,决不对外公佈。
  • 为提供精确的服务,我们会将收集的问卷调查内容进行统计与分析,分析结果之统计数据或说明文字呈现,除供内部研究外,我们会视需要公佈统计数据及说明文字,但不涉及特定个人之资料。
  • 您可以随时向我们提出请求,以更正或删除您的帐户或本网站所蒐集的个人资料等隐私资讯。联繫方式请见最下方联繫管道。

三、资料之保护

  • 本网站主机均设有防火牆、防毒系统等相关的各项资讯安全设备及必要的安全防护措施,加以保护网站及您的个人资料採用严格的保护措施,只由经过授权的人员才能接触您的个人资料,相关处理人员皆签有保密合约,如有违反保密义务者,将会受到相关的法律处分。
  • 如因业务需要有必要委託其他单位提供服务时,本网站亦会严格要求其遵守保密义务,并且採取必要检查程序以确定其将确实遵守。

四、网站对外的相关连结

本网站的网页提供其他网站的网路连结,您也可经由本网站所提供的连结,点选进入其他网站。但该连结网站不适用本网站的隐私权保护政策,您必须参考该连结网站中的隐私权保护政策。

五、与第三人共用个人资料之政策

本网站绝不会提供、交换、出租或出售任何您的个人资料给其他个人、团体、私人企业或公务机关,但有法律依据或合约义务者,不在此限。

前项但书之情形包括不限于:

  • 经由您书面同意。
  • 法律明文规定。
  • 为免除您生命、身体、自由或财产上之危险。
  • 与公务机关或学术研究机构合作,基于公共利益为统计或学术研究而有必要,且资料经过提供者处理或蒐集着依其揭露方式无从识别特定之当事人。
  • 当您在网站的行为,违反服务条款或可能损害或妨碍网站与其他使用者权益或导致任何人遭受损害时,经网站管理单位研析揭露您的个人资料是为了辨识、联络或採取法律行动所必要者。
  • 有利于您的权益。

本网站委託厂商协助蒐集、处理或利用您的个人资料时,将对委外厂商或个人善尽监督管理之责。

六、Cookie之使用

为了提供您最佳的服务,本网站会在您的电脑中放置并取用我们的Cookie,若您不愿接受Cookie的写入,您可在您使用的浏览器功能项中设定隐私权等级为高,即可拒绝Cookie的写入,但可能会导至网站某些功能无法正常执行 。

七、隐私权保护政策之修正

本网站隐私权保护政策将因应需求随时进行修正,修正后的条款将刊登于网站上。

八、联繫管道

对于本站之隐私权政策有任何疑问,或者想提出变更、移除个人资料之请求,请前往本站「联络我们」页面提交表单。

Privacy Policy

Last updated: [2024/11/17]

Introduction

Welcome to programnotes.cn . We are committed to protecting your privacy. This Privacy Policy explains how we collect, use, disclose, and safeguard your information when you visit our website and use our services. Please read this privacy policy carefully. If you do not agree with the terms of this privacy policy, please do not access the site.

Data Controller

The data controller responsible for your personal data is the company operating this website. For the data controller information, please refer to the “Contact Us” section at the end of this policy.

Information Collection

We may collect information about you in a variety of ways. The information we may collect on the Site includes:

  • Personal Data: Personally identifiable information, such as your name, email address, and telephone number, and demographic information, such as your age, gender, hometown, and interests, that you voluntarily give to us when you register with the Site or when you choose to participate in various activities related to the Site.
  • Derivative Data: Information our servers automatically collect when you access the Site, such as your IP address, your browser type, your operating system, your access times, and the pages you have viewed directly before and after accessing the Site.
  • Data From Social Networks: User information from social networking sites, including your name, your social network username, email address and profile picture, if you connect your account to such social networks.

Use of Your Information

Having accurate information about you permits us to provide you with a smooth, efficient, and customized experience. Specifically, we may use information collected about you via the Site to:

  • Create and manage your account.
  • Send you administrative information, such as information about changes to our terms, conditions, and policies.
  • Improve our services and operations.
  • Understand and analyze how you use our Site and services, which can improve our overall functionality.
  • Communicate with you, either directly or through one of our partners, including for customer service, to provide you with updates and other information relating to the Site, and for marketing and promotional purposes.
  • Detect and prevent fraudulent transactions and other illegal activities.

Disclosure of Your Information

We may share information we have collected about you in certain situations. Your information may be disclosed as follows:

  • By Law or to Protect Rights: If we believe the release of information about you is necessary to respond to legal process, to investigate or remedy potential violations of our policies, or to protect the rights, property, and safety of others, we may share your information as permitted or required by any applicable law, rule, or regulation.
  • Business Transfers: We may share or transfer your information in connection with, or during negotiations of, any merger, sale of company assets, financing, or acquisition of all or a portion of our business to another company.
  • Third-Party Service Providers: We may share your information with third parties that perform services for us or on our behalf, including data analysis, email delivery, hosting services, customer service, and marketing assistance.

Security of Your Information

We use administrative, technical, and physical security measures to help protect your personal information. While we have taken reasonable steps to secure the personal information you provide to us, please be aware that despite our efforts, no security measures are perfect or impenetrable, and no method of data transmission can be guaranteed against any interception or other type of misuse.

Policy for Children

We do not knowingly solicit information from or market to children under the age of 13. If we learn that we have collected personal information from a child under age 13 without verification of parental consent, we will delete that information as quickly as possible. If you believe we might have any information from or about a child under 13, please contact us.

User Rights

You have the following rights concerning your data:

  • Right to Access: You can request information about the personal data we hold about you.
  • Right to Rectification: You have the right to request correction of inaccurate personal data we have about you.
  • Right to Erasure: You can request that we delete your personal data.
  • Right to Restrict Processing: You have the right to request the restriction of processing your personal data.
  • Right to Data Portability: You can request a copy of your personal data in a structured, commonly used, and machine-readable format.
  • Right to Object: You have the right to object to the processing of your personal data.

To exercise any of these rights, please contact us using the information provided below.

Changes to This Privacy Policy

We may update this Privacy Policy from time to time in order to reflect, for example, changes to our practices or for other operational, legal, or regulatory reasons. We will notify you of any changes by posting the new Privacy Policy on this page. You are advised to review this Privacy Policy periodically for any changes.

Contact Us

If you have questions or comments about this Privacy Policy, please go to “Contact Us” page on this website