https://www.gravatar.com/avatar/5f48da38e786436afece6f2e46196202?s=240&d=mp

Linux Shell

Limit the maximum number of Goroutine and Using channel communication Demo

//statics.lshell.com/home-gopher.png

今天学习了一下 GoLang 协程和及其通信,写了一下 Demo

  
package main  
  
import (  
 "fmt"  
 "strconv"  
 "sync"  
 "time"  
)  
  
// Maximum goroutine  
const goSize = 5  
  
// Producer Producer  
type Producer struct {  
 Item string  
}  
  
// Result result struct  
type Result struct {  
 Code   int  
 Stdout string  
}  
  
// RunJob job  
func RunJob(item string) (result Result) {  
 result.Code = 200  
 result.Stdout = item  
 return  
}  
  
// RoutineRun  go routine run job  
func RoutineRun(wg *sync.WaitGroup, producers chan Producer, result chan Result) {  
 for i := 0; i < goSize; i++ {  
  wg.Add(1)  
  go func() {  
   defer wg.Done()  
   for producer := range producers {  
    time.Sleep(time.Second)  
    ret := RunJob(producer.Item)  
    result <- ret  
   }  
  }()  
 }  
}  
  
func main() {  
 var job Producer  
 wg := &sync.WaitGroup{}  
 jobCount := 20  
 // chan size cannot be smaller than jobCount  
 jobsChan := make(chan Producer, 100)  
 resultChan := make(chan Result, 100)  
  
 for i := 0; i < jobCount; i++ {  
  job.Item = "item: " + strconv.Itoa(i)  
  jobsChan <- job  
 }  
 close(jobsChan)  
  
 RoutineRun(wg, jobsChan, resultChan)  
 wg.Wait()  
 close(resultChan)  
  
 for {  
  ret, ok := <-resultChan  
  if !ok {  
   break  
  }  
  fmt.Println("code: ", ret.Code, "stdout", ret.Stdout)  
 }  
}  
  
  

Github上的高星项目

  1. tunny is a Golang library for spawning and managing a goroutine pool, allowing you to limit work coming from any number of goroutines with a synchronous API.
  2. ants 是一个高性能的 goroutine 池,实现了对大规模 goroutine 的调度管理、goroutine 复用,允许使用者在开发并发程序的时候限制 goroutine 数量,复用资源,达到更高效执行任务的效果。

Mac 使用中的各种问题

https://statics.lshell.com/FAQ.png
记录一下 在我使用Mac过程中遇到的问题及其解决方案。

1、LaunchPad 删除 App 出现问题的情况处理:

defaults write com.apple.dock ResetLaunchPad -bool true;killall Dock  

```注意:此命令会将你安装的应用全部移到第二页,并且不会保留目录  
2、修复 mac VNC 连接黑屏,=> [Via](http://www.macminiworld.net/fix-the-black-screen-on-mac-os-x-vnc/)  

sudo killall loginwindow

Mac 终端高亮

Mac 下的终端居然没有高亮。

先看最终效果:

https://statics.lshell.com/terminal-highlighting.png

将以下代码拷贝到 ~/.bash_profile 中:

#enables colorin the terminal bash shell export  
export CLICOLOR=1  
#sets up thecolor scheme for list export  
export LSCOLORS=gxfxcxdxbxegedabagacad  
#sets up theprompt color (currently a green similar to linux terminal)  
export PS1='[033[01;32m]u@h[033[00m]:[033[01;36m]w[033[00m]$ '  
#enables colorfor iTerm  
export TERM=xterm-color  

```使~/.bash_profile生效 运行以下命令,或者重启终端  

source ~/.bash_profile

Win 10 XShell 6 经常未响应

作为一个运维,每天有8个小时都在使用 Xshell ,基本每天要开几十个窗口,虽然大部分操作都写在了WEB后台,但是仍然会有Xshell的需求;不知从何时起,同时打开多个(大于3)ssh 连接的时候,Xshell 大概率的会导致未响应,偶然在官方论坛上找到了解决方案:

SVN:E200030: sqlite[S11]: database disk image is malformed

When I tried svn up, I got an error.

E200030: sqlite[S11]: database disk image is malformed  

```I found a solution on [stackoverflow](https://stackoverflow.com/questions/13675615/svn-cleanup-sqlite-database-disk-image-is-malformed).```
sqlite3 .svn/wc.db "pragma integrity_check"  
sqlite3 .svn/wc.db "reindex nodes"  
sqlite3 .svn/wc.db "reindex pristine"  

2018 我们一起走过

https://statics.lshell.com/2019-life.jpg

工作

于今年6月份离开了上家公司,在现在的公司中又变成了我一人单独搞运维工作了,想起这几年来,不知道是什么原因,我总是会因这样那样的问题导致我始终在单干,没有同行的交流学习,其实我是一个自律性比较差的人,不愿去想太多,一般都只是抱着完成任务的心态去做,不会计划,或者说不会去执行,很多事情都靠三分钟热度。比起大D的有计划有执行力差得太远,包括写总结也是跟大D学的。