<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">

  <title><![CDATA[t3reezhou]]></title>
  <link href="t3reezhou.github.io/atom.xml" rel="self"/>
  <link href="t3reezhou.github.io/"/>
  <updated>2019-03-04T11:59:51+08:00</updated>
  <id>t3reezhou.github.io/</id>
  <author>
    <name><![CDATA[]]></name>
    
  </author>
  <generator uri="http://www.coderforart.com/">CoderForArt</generator>

  
  <entry>
    <title type="html"><![CDATA[超时表象]]></title>
    <link href="t3reezhou.github.io/15516707139709.html"/>
    <updated>2019-03-04T11:38:33+08:00</updated>
    <id>t3reezhou.github.io/15516707139709.html</id>
    <content type="html"><![CDATA[
<pre><code class="language-go">package main

import (
    &quot;context&quot;
    &quot;errors&quot;
    &quot;fmt&quot;
    &quot;time&quot;
)

func main() {
    ctx, cancle := context.WithTimeout(context.Background(), time.Second*5)
    defer cancle()
    fmt.Println(&quot;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&quot;, T2(ctx))

}

func T(ctx context.Context) []int {
    c := make(chan int)
    go func() {
        for i := 0; i &lt; 10; i++ {
            c &lt;- i
            time.Sleep(1 * time.Second)
        }
        close(c)
    }()
    result := make([]int, 0)
    for {
        var (
            ok bool
            x  int
        )
        select {
        case x, ok = &lt;-c:
            fmt.Println(&quot;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&quot;, x)
            result = append(result, x)
        case &lt;-ctx.Done():
            fmt.Println(&quot;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;timeout&quot;)
        }
        if !ok {
            break
        }
    }
    return result
}

func T2(ctx context.Context) []int {
    c := make(chan error)
    result := make([]int, 0)
    go func() {
        defer close(c)

        for i := 0; i &lt; 10; i++ {
            result = append(result, i)
            c &lt;- errors.New(&quot;hahahah&quot;)
            time.Sleep(1 * time.Second)
        }
    }()
    for {
        select {
        case x, ok := &lt;-c:
            fmt.Println(&quot;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&quot;, x)
            if !ok {
                return result
            }
        case &lt;-ctx.Done():
            fmt.Println(&quot;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;timeout&quot;)
            return result
        }
    }
}

func T3() []int {
    c := make(chan error)
    result := make([]int, 0)
    go func() {
        defer close(c)

        for i := 0; i &lt; 10; i++ {
            result = append(result, i)
            c &lt;- errors.New(&quot;hahahah&quot;)
            time.Sleep(1 * time.Second)
        }
    }()
    for {
        select {
        case x, ok := &lt;-c:
            fmt.Println(&quot;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&quot;, x)
            if !ok {
                return result
            }
        case &lt;-time.After(time.Second * 5):
            fmt.Println(&quot;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;timeout&quot;)
            return result
        }
    }
}

func T4() []int {
    c := make(chan error)
    result := make([]int, 0)
    go func() {
        defer close(c)
        for i := 0; i &lt; 10; i++ {
            result = append(result, i)
            c &lt;- errors.New(&quot;hahahah&quot;)
            time.Sleep(6 * time.Second)
        }
    }()
    for {
        select {
        case x, ok := &lt;-c:
            fmt.Println(&quot;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&quot;, x)
            if !ok {
                return result
            }
        case &lt;-time.After(time.Second * 5):
            fmt.Println(&quot;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;timeout&quot;)
            return result
        }
    }
}

func T5() []int {
    c := make(chan error)
    result := make([]int, 0)
    go func() {
        defer close(c)
        for i := 0; i &lt; 10; i++ {
            result = append(result, i)
            c &lt;- errors.New(&quot;hahahah&quot;)
            time.Sleep(6 * time.Second)
        }
    }()
    for timeOut := time.After(time.Second * 20); ; {
        select {
        case x, ok := &lt;-c:
            fmt.Println(&quot;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&quot;, x)
            if !ok {
                return result
            }
        case &lt;-timeOut:
            fmt.Println(&quot;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;timeout&quot;)
            return result
        }
    }
}

</code></pre>

]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[延迟运行func中的指针问题]]></title>
    <link href="t3reezhou.github.io/15516705202360.html"/>
    <updated>2019-03-04T11:35:20+08:00</updated>
    <id>t3reezhou.github.io/15516705202360.html</id>
    <content type="html"><![CDATA[
<pre><code class="language-go"># package main

import &quot;fmt&quot;

func main() {
    origin := []int{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}
    s := func(i int) func() {
        return func() {
            fmt.Println(&quot;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&quot;, i)
        }
    }(origin[9])

    origin[9] = 10
    s() // output: &gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; 9
    origin = append([]int{-1}, origin...)
    s() // output: &gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; 9
    s2 := func(i *int) func() {
        return func() {
            fmt.Println(&quot;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&quot;, *i)
        }
    }(&amp;(origin[9]))
    s2() // output: &gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; 8
    origin[9] = 9
    s2() // output: &gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; 9
}
</code></pre>

]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[六大原则]]></title>
    <link href="t3reezhou.github.io/15511520390847.html"/>
    <updated>2019-02-26T11:33:59+08:00</updated>
    <id>t3reezhou.github.io/15511520390847.html</id>
    <content type="html"><![CDATA[
<ol>
<li>职责单一原则</li>
<li>里式替换原则</li>
<li>依赖倒置原则</li>
<li>接口隔离原则</li>
<li>迪米特原则</li>
<li>开闭原则</li>
</ol>

]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[高可用]]></title>
    <link href="t3reezhou.github.io/15401753860167.html"/>
    <updated>2018-10-22T10:29:46+08:00</updated>
    <id>t3reezhou.github.io/15401753860167.html</id>
    <content type="html"><![CDATA[
<p>衡量一个系统架构设计是否满足高可用的目标，就是假设系统中任何一台或者多台服务器宂机时，以及出现各种不可预期的问题时，系统整体是否依然可用</p>

<h2 id="toc_0">伸缩性</h2>

<p>所谓伸缩性时指通过不断向集群中加入服务器的手段来缓解不断上升的用户并发访问压力和不断增长的数据存储需求</p>

<p>衡量架构伸缩性的主要标准就是是否可以用多台服务器构建集群，是否容易向集群中添加新的服务器，加入新的服务器后是否可以提供和原来的服务器无差别的服务，集群中可容纳的总的服务器数量是否有限制</p>

<h2 id="toc_1">拓展性</h2>

<p>衡量网站架构拓展性好坏的主要标准就是在网站增加新的业务产品时，是否可以实现对现有产品透明无影响，不需要任何改动或者很少改动既有业务功能就可以上线新产品。不同产品之间是否很少耦合，一个产品改动对其他产品无影响，其他产品和功能不需要受牵连进行改动</p>

]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[矩阵空间压缩方法]]></title>
    <link href="t3reezhou.github.io/15392434025926.html"/>
    <updated>2018-10-11T15:36:42+08:00</updated>
    <id>t3reezhou.github.io/15392434025926.html</id>
    <content type="html"><![CDATA[
<p>在动态规划里，如果只是得到结果而非过程，实际可以不记录整个矩阵，可以压缩为min(m,n)<br/>
在最短路径问题里，如果只是要得出最短路径和的话，可以用到这个技巧</p>

]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[实现数组倒序]]></title>
    <link href="t3reezhou.github.io/15233326936347.html"/>
    <updated>2018-04-10T11:58:13+08:00</updated>
    <id>t3reezhou.github.io/15233326936347.html</id>
    <content type="html"><![CDATA[
<pre><code class="language-go">package main

import (
    &quot;fmt&quot;
    &quot;sort&quot;
    &quot;strings&quot;
)

func main() {
    god := []string{&quot;g&quot;, &quot;o&quot;, &quot;d&quot;}
    sort.SliceStable(god, func(i, j int) bool { return i &gt; j })
    fmt.Printf(&quot;god is %s&quot;, strings.Join(god,&quot;&quot;))
}
</code></pre>

<p>output is : god is dog</p>

]]></content>
  </entry>
  
</feed>
