GithubHelp home page GithubHelp logo

articles's People

articles's Issues

单机支持6w并发

背景

进度

tsung使用每秒6000的用户去压测nginx,但是最高吞吐量是3000+/s,因此需要看看是什么问题,导致nginx的并发连接数这么低。

<?xml version="1.0"?>
<!DOCTYPE tsung SYSTEM "/usr/local/tsung/share/tsung/tsung-1.0.dtd">
<tsung loglevel="notice" version="1.0">

  <!-- Client side setup -->
  <clients>
    <client host="localhost" maxusers="60000"  use_controller_vm="true"/>
  </clients>

  <!-- Server side setup -->
<servers>
  <server host="centos2" port="80" type="tcp"></server>
</servers>

  <!-- to start os monitoring (cpu, network, memory). Use an erlang
  agent on the remote machine or SNMP. erlang is the default -->

  <monitoring>
    <monitor host="centos1" type="snmp"></monitor>
  </monitoring>


<load>
  <arrivalphase phase="1" duration="60" unit="minute">
    <users maxnumber="60000000" arrivalrate="6000" unit="second"></users>
  </arrivalphase>
</load>
<options>
<option name="tcp_reuseaddr" value="true"></option>
<option name="connect_timeout" value="1000"></option>
<option name="idle_timeout" value="300000"></option>
<option name="global_ack_timeout" value="6000000"></option>

<option name="max_retries" value="0"></option>
<option name="tcp_snd_buffer" value="16384"></option>
<option name="tcp_rcv_buffer" value="16384"></option>
</options>

<sessions>
        <session name="foo" probability="100" type="ts_http">
            <request> <http url="/?e=1" method="GET"></http> </request>
        </session>
</sessions>

</tsung>

nginx 配置


user  nginx;
worker_processes  1;
worker_rlimit_nofile 302400;


error_log  /var/log/nginx/error.log crit;
pid        /var/run/nginx.pid;


events {
    use epoll;
    worker_connections  20480;
multi_accept on;
}


http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    #access_log  /var/log/nginx/access.log  main;
    access_log off;

    sendfile        on;
    tcp_nopush     on;
    tcp_nodelay on;
    keepalive_requests 1;
    reset_timedout_connection on;
    client_body_timeout 10;
    send_timeout 2;


    keepalive_timeout  30;

    #gzip  on;

    open_file_cache max=200000 inactive=20s;
    open_file_cache_valid 30s;
    open_file_cache_min_uses 2;
    open_file_cache_errors on;

    include /etc/nginx/conf.d/*.conf;
}

不加班指南

了解业务

快速了解业务。先了解核心部分,然扩展去了解没那么重要的部分。

初步认识系统

不求对系统了如指掌,但是要认真了解系统的核心部分的实现逻辑。

并发压测

想象在量很大的情况下,系统会出现哪些问题,怎么做可以让系统扛得住。如何模拟并发请求,去进行压测。
#监控
系统有哪些重要的监控指标是需要做好系统监控。

快速编写代码

准备常用的代码块Controller层、Service层、Dao层(mybatis),SQL写法,常用的ER设计模型直接复制黏贴。
Controller层代码
Service层代码
Dao层代码
SQL写法
关联查询
ER设计模型

熟悉旧代码

修改代码前,当要确定一个变量被哪些地方引用时,使用IDEA插件去查看这个变量在哪里被用到,修改回造成什么后果。(未找到这种插件)
重构代码,让后面接手的人也很舒服接手项目。
重构规则:

解决线上问题

将平时会遇到的问题的解决办法提炼出来。准备常用解决问题的方法。让自己的工作效率快起来。

#接手项目
接手项目的时候太痛苦了,要不就是代码写得不好,要不就缺失相关文档。
为了所有程序员的幸福度,我觉得要制定一个规约,全网程序员按照这种规约来执行。那么无论你去到哪家公司,看到的代码写法是一致,那该有多幸福。
要做到下面这几部分:

规约

命名。尽量使用简单的命名,因为我们的英文水平真的需要提高,命名得不好。无法真实描述你想表达的意思。
一个方法要么是返回值,要不是传参,然后在方法里对这个参数进行修改,不能同时进行。

测试第三方jar包的项目
我们使用第三方jar包功能,但是我们要测试他们的API使用,这时就可以跳到另外一个项目进行测试API的操作。
git上搜索demo合集

写代码过程

先写框架,然后写细节。待办加上TODO

#排查问题
打日志要将请求参数和响应打印出来,方便排查问题。
准备常用查看数据的sql语句,排查时可以直接复制。

需求文档接口文档

需要由代码端来保存,产品经理才不管你这么多呢。

#mysql数据库设计
字段必须写注释
关联字段必须指定另外一个表的名称

责任划分,不要响应不属于你的问题,叫他们找对应的人

了解知乎小伙伴提供的意见参考:
https://www.zhihu.com/question/28919418

如何像JDK源码写Java注释

用<p>换行 
用{@link 类路径} 来链接到其他类 
用<pre></pre>包住代码 
用{@code 方法名}来表示某个单词是一个方法名或者变量名
用<a href="http://www.baidu.com"></a>来做一个外部链接

chrome插件regex search 支持拷贝功能

背景:

有朋友需要在页面上用正则搜索手机号,然后自动复制(不用手动拷贝)。然后就在chrome插件上搜索到有regex search。但是没有找到带copy功能的,所以打算自己修改下源代码,满足自己的需求。

初步想法:

1.查看原来regex search的源代码。(参考这篇文章 http://ju.outofmemory.cn/entry/254528)
2.修改源代码。
3.使用开发者模式,将修改后的插件文件夹拖动的chrome插件管理页面上即可。(这里要注意假如修改了content.js,每次要卸掉插件,然后重新拖动进去才会生效)

我要使用js的复制功能,所以参考了这篇文章(https://juejin.im/post/5a94f8eff265da4e9b593c29)。
其中最重要的代码段是

        const input = document.createElement('input');
	document.body.appendChild(input);
 	input.setAttribute('value', '听说你想复制我');
	input.select();
	if (document.execCommand('copy')) {
		document.execCommand('copy');
		console.log('复制成功');
	}
        document.body.removeChild(input);

作者:axuebin
链接:https://juejin.im/post/5a94f8eff265da4e9b593c29
来源:掘金
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。

以下修改了Regex Search的content.js的源码。

function highlight(regex, highlightColor, selectedColor, textColor, maxResults) {
  function highlightRecursive(node) {
    if(searchInfo.length >= maxResults){
      return;
    }
    if (isTextNode(node)) {
      var index = node.data.search(regex);
      if (index >= 0 && node.data.length > 0) {
        var matchedText = node.data.match(regex)[0];
        
        //每次高亮html里的文本的时候执行一遍复制功能
        const input = document.createElement('input');
        input.setAttribute('type', 'hidden');
        document.body.appendChild(input);
        input.setAttribute('value', matchedText);
        input.select();
        if (document.execCommand('copy')) {
          document.execCommand('copy');
          console.log('复制成功');
        }
        document.body.removeChild(input);

        var matchedTextNode = node.splitText(index);
        matchedTextNode.splitText(matchedText.length);
        var spanNode = document.createElement(HIGHLIGHT_TAG); 
        spanNode.className = HIGHLIGHT_CLASS;
        spanNode.style.backgroundColor = highlightColor;
        spanNode.style.color = textColor;
        spanNode.appendChild(matchedTextNode.cloneNode(true));
        matchedTextNode.parentNode.replaceChild(spanNode, matchedTextNode);
        searchInfo.highlightedNodes.push(spanNode);
        searchInfo.length += 1;
        return 1;
      }
    } else if (isExpandable(node)) {
        var children = node.childNodes;
        for (var i = 0; i < children.length; ++i) {
          var child = children[i];
          i += highlightRecursive(child);
        }
    }
    return 0;
  }
  highlightRecursive(document.getElementsByTagName('body')[0]);
};
function search(regexString, configurationChanged) {
  var regex = validateRegex(regexString);
  if (regex && regexString != '' && (configurationChanged || regexString !== searchInfo.regexString)) { // new valid regex string
    removeHighlight();
    chrome.storage.local.get({
      'highlightColor' : DEFAULT_HIGHLIGHT_COLOR,
      'selectedColor' : DEFAULT_SELECTED_COLOR,
      'textColor' : DEFAULT_TEXT_COLOR,
      'maxResults' : DEFAULT_MAX_RESULTS,
      'caseInsensitive' : DEFAULT_CASE_INSENSITIVE}, 
      function(result) {
        initSearchInfo(regexString);
        if(result.caseInsensitive){
          regex = new RegExp(regexString, 'i');
        }

       //每次初始化搜索时,将"无"复制到剪贴板
       const input = document.createElement('input');
       input.setAttribute('type', 'hidden');
        document.body.appendChild(input);
        input.setAttribute('value', '无');
        input.select();
        if (document.execCommand('copy')) {
          document.execCommand('copy');
          console.log('复制成功');
        }
        document.body.removeChild(input);
        

        highlight(regex, result.highlightColor, result.selectedColor, result.textColor, result.maxResults);
        selectFirstNode(result.selectedColor);
        returnSearchInfo('search');
      }
    );
  } else if (regex && regexString != '' && regexString === searchInfo.regexString) { // elements are already highlighted
    chrome.storage.local.get({
      'highlightColor' : DEFAULT_HIGHLIGHT_COLOR,
      'selectedColor' : DEFAULT_SELECTED_COLOR}, 
      function(result) {
        selectNextNode(result.highlightColor, result.selectedColor);
      }
    );
  } else { // blank string or invalid regex
    removeHighlight();
    initSearchInfo(regexString);
    returnSearchInfo('search');
  }
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.