github.com/graybobo/golang.org-package-offline-cache@v0.0.0-20200626051047-6608995c132f/x/talks/2014/gocon-tokyo.slide (about)

     1  Go: 90% Perfect, 100% of the time.
     2  "GoCon Tokyo"
     3  31 May 2014
     4  Tags: go, gocon
     5  
     6  Brad Fitzpatrick
     7  @bradfitz
     8  bradfitz@golang.org
     9  http://bradfitz.com
    10  http://camlistore.org
    11  
    12  * Hello!
    13  
    14  * "60% of the time, it works every time...."
    15  
    16  .image gocon-tokyo/60p.jpg
    17  
    18  * "That makes no sense"
    19  
    20  * Starting a new project, picking a language...
    21  
    22  * Disclaimer
    23  
    24  - Personal experience only
    25  - My opinions
    26  - Fake, fun numbers (e.g. "90% Perfect, 100% of the time.")
    27  - Maybe it's 91%.
    28  - All languages are both wonderful and terrible
    29  - <3
    30  
    31  * 2010
    32  
    33  * Idea: Camlistore
    34  
    35  - All my life's data from everywhere,
    36  - Import, backup, serve, browse, search, share, index
    37  - Designed to last 100+ years
    38  - Don't trust any company
    39  - In 2010: an idea
    40  - In 2014: busy, fun, active project
    41  
    42  * Which language to use for Camlistore?
    43  
    44  * Before Go
    45  
    46  - Starting a new project from 1994 ~ 2010...
    47  - Perl or C?
    48  - Rarely but occasionally Java.
    49  
    50  * Perl: The Good
    51  
    52  - Fun
    53  - Expressive
    54  - Get things done, quickly
    55  
    56  * Python, Ruby, Javascript: The Good
    57  
    58  - Same
    59  
    60  * Perl: The Bad
    61  
    62  - Not fast like C
    63  - Sometimes need to write in C
    64  - ... or write in XS (Perl-C glue language)
    65  - Perl-C, C-Perl calls are slow
    66  - Single-threaded, single-core, callback hell
    67  
    68  * Python, Ruby, Javascript: The Bad
    69  
    70  - Same, but even slower :)
    71  - JavaScript is faster now, but not as fast as C
    72  
    73  * Summary
    74  
    75  - Perlythonubyscript: slow for computer, fast & fun for human
    76  - C: slow for human, fast for computer
    77  - C++: little more fun than C, but more complexity
    78  - Java: tedious (verbose), slow start-up, easy to find programmers
    79  - PHP: if somebody's paying you enough, maybe
    80  
    81  * Fun vs. fast
    82  
    83  .image gocon-tokyo/funfast-nogo.svg
    84  
    85  * Maybe mix of two languages?
    86  
    87  - Fun, slow parts in Perlythonubyscript?
    88  - Important, fast parts in C?
    89  
    90  * But...
    91  
    92  - You'll want to share code.
    93  - Calling from C to X or X to C is slow.
    94  - The C-X glue language is the least fun language
    95  - You'll be lazy, and write in the fun language
    96  - Or be lazy and waste time, and write too much stuff in C++ (like Google)
    97  
    98  * Server? Threads or events?
    99  
   100  * Threads
   101  
   102  - C, C++, Java, ...
   103  - Threads? Heavy. Lots of memory per thread for stacks. Be careful!
   104    Executor pool = new ScheduledThreadPoolExecutor(/* ???? guess a number */);
   105  
   106  * Events
   107  
   108  - Perlythonubyscript: events. no choice. Callback hell.
   109  - C, C++: libevent, etc. Callback hell.
   110  
   111  .image gocon-tokyo/spaghetti.jpg
   112  
   113  - C#: await async await async await async await async noise
   114  
   115  * Concurrency and performance
   116  
   117  .image gocon-tokyo/concurrency0.svg
   118  
   119  * It's really hard to pick a language!
   120  
   121  * 2010. Let's try Go!
   122  
   123  * Go: 90% Perfect, 100% of the time.
   124  
   125  * Go: 90% Perfect, 100% of the time.
   126  
   127  - Go is very good at lots of things
   128  - High-level code when you want
   129  - Low-level code when you want
   130  - Start high, profile, go low-level when needed
   131  - Static typing without too much keyboard typing
   132  
   133  * Before Go
   134  
   135  .image gocon-tokyo/funfast-nogo.svg
   136  
   137  * After Go
   138  
   139  .image gocon-tokyo/funfast.svg
   140  
   141  * Go's Concurrency
   142  
   143  - Built-in! Lightweight threads, no callback hell
   144  - Readable, top-down code
   145  - So easy to write servers
   146  
   147    for {
   148      conn, err := listener.Accept()
   149      // check err
   150      go serve(conn)
   151    }
   152  
   153  - Goroutine-per-request can scale
   154  
   155  * Concurrency before Go
   156  
   157  .image gocon-tokyo/concurrency0.svg
   158  
   159  * After Go
   160  
   161  .image gocon-tokyo/concurrency.svg
   162  
   163  * Go is showing up for all sorts of tasks
   164  
   165  * Web frameworks
   166  
   167  - Typically a job for scripting languages: Node.js, Python, Ruby, Perl, PHP, etc.
   168  - net/http in the standard library
   169  - Other http frameworks on top: gorilla, martini, Revel etc...
   170  - No need for nginx: standard library's http server scales
   171  
   172  * Image processing
   173  
   174  - no libpng, imagemagick, etc
   175  - pure Go PNG, JPEG, GIF encoding & decoding in the standard library
   176  - slower, but safer
   177  - getting faster
   178  
   179  * Crypto
   180  
   181  - no OpenSSL, no GnuTLS
   182  - pure Go AES, TLS (SSL), OpenPGP, etc
   183  - slower, but safer
   184  - getting faster
   185  
   186  * Replacing shell scripts
   187  
   188  - Instead of little Perl & shell scripts, I now write in Go
   189  - os/exec package & goroutines makes subprocess management easier than shell
   190  
   191  * Camlistore
   192  
   193  - web handlers
   194  - using third-party web APIs
   195  - image thumbnails: decode, resize, encode
   196  - EXIF, ID3 parsing
   197  - database drivers
   198  - crypto, image decoding/resizing/encoding
   199  - search, indexing: tight memory layout control
   200  - WebSockets, HTTPS
   201  - all pure Go!
   202  
   203  * Controlling flying drones
   204  
   205  .link http://www.godrone.io
   206  - "Isn’t Go unsuitable for real-time applications like this?"
   207  - "However, for all practical purposes the GC just needs to keep up with the stabilization loop which runs at 200 Hz. This means that GC pauses below 5ms have no impact on performance. Longer pauses will degrade stabilization performance, but the tolerance threshold may be up to a second ..." (small heap)
   208  
   209  .image gocon-tokyo/drone.png
   210  
   211  * Emulators
   212  
   213  .link http://dave.cheney.net/2013/01/09/go-the-language-for-emulators Go: The Language For Emulators
   214  
   215  .image gocon-tokyo/trs.png
   216  
   217  * Disassembler, linker, compiler.
   218  
   219  - llgo compiler (Go -> LLVM IR -> ...)
   220  - Go 1.3's disassembler
   221  - Go 1.4's linker
   222  - Go 1.4 or Go 1.5's compiler
   223  
   224  * Mobile
   225  
   226  - Go runs on ARM
   227  - minux's iOS port of Go
   228  - Camlistore child process, goandroid
   229  
   230  .image gocon-tokyo/goandroid.png
   231  
   232  * Audio synthesis
   233  
   234  - https://github.com/nf/sigourney
   235  
   236  .image gocon-tokyo/sigourney.png
   237  
   238  * Cloud infrastructure
   239  
   240  .link http://redmonk.com/dberkholz/2014/03/18/go-the-emerging-language-of-cloud-infrastructure/ Go: the emerging language of cloud infrastructure
   241  
   242  - Docker, Packer
   243  - CoreOS’s etcd and fleet
   244  - Ubuntu Juju, Mozilla Heka, Apcera’s NATS, gnatsd
   245  
   246  .image gocon-tokyo/docker.png
   247  
   248  * Load balancers & servers
   249  
   250  - YouTube's vitess: MySQL
   251  - net/http/httputil.ReverseProxy
   252  - dl.google.com
   253  - etc
   254  
   255  * Raspberry Pi GPIO
   256  
   257  .link https://github.com/davecheney/gpio
   258  .link https://github.com/stianeikeland/go-rpio
   259  .link https://github.com/luismesas/goPi
   260  
   261  .image gocon-tokyo/gpio.gif
   262  
   263  * What other language is used for all these?
   264  
   265  - web apps
   266  - scripts
   267  - system administration
   268  - image processing
   269  - load balancers, servers
   270  - crypto
   271  - hardware
   272  
   273  Go!
   274  
   275  * And even better...
   276  
   277  * Go built-in tools
   278  
   279  - testing
   280  - benchmarking
   281  - profiling (CPU, memory, blocking)
   282  - huge standard library
   283  - "go get"
   284  - godoc
   285  - gofmt, goimports
   286  - race detector
   287  - static binaries
   288  
   289  * So why isn't Go perfect?
   290  
   291  * Generics
   292  
   293  - No generics
   294  - It sucks sometimes, but rarely
   295  - Use maps, slices, interfaces
   296  - Occasionally a gross interface{}
   297  - No algorithms in stdlib
   298  - No great proposal yet
   299  
   300  * No generics (Simon Peyton Jones: "Haskell is useless")
   301  
   302  .image gocon-tokyo/generics.svg
   303  
   304  * Data races can happen
   305  
   306  - shared, mutable state is possible
   307  - use channels
   308  - be careful
   309  - conventions and documentation help
   310  - runtime race detector helps too
   311    $ go test -race
   312  * Code generation
   313  
   314  - The default Go compiler often generates pretty dumb code
   315  - Especially on ARM
   316  - But getting better
   317  - In Go 1.4, 1.5+: Go compiler in Go, refactor, add SSA, more optimizations
   318  
   319  * gccgo
   320  
   321  - gccgo generates very good code
   322  - ... but lacks escape analysis: kills performance with many small allocs + garbage
   323  - ... GC isn't precise. Bad for 32-bit.
   324  
   325  * Compiling to JavaScript isn't yet great
   326  
   327  - Would be nice to write frontend & backend in the same language, share code
   328  - go/types + go/ssa enables many things:
   329  .link http://tardisgo.github.io/ TARDIS Go Compiler
   330  .image gocon-tokyo/tardis.png
   331  
   332  * Limited Mobile Support
   333  
   334  - No built-in Android support (but goandroid, child processes...)
   335  - No built-in iOS support (but unmerged port...)
   336  
   337  * Embedding Go in C/C++/Java/etc
   338  
   339  - Can't embed Go in other languages, environments.
   340  - e.g. Android, iOS, C/C++ programs
   341  - problems with memory setup, GC, signals, ...
   342  - need embedding API design
   343  - In Go 1.4?
   344  
   345  * Shared libraries
   346  
   347  - no shared libraries
   348  - can't load Go code at runtime
   349  
   350  * Garbage collector
   351  
   352  - Pauses: faster each release, good people working on it.
   353  - Precision: heap in 1.2, most stacks in 1.3, more in 1.4.
   354  - 4 versions of memcached: Perl, C, C++, Go
   355  
   356  * Hot stack splits
   357  
   358  - Almost entirely fixed in Go 1.3's contiguous stacks
   359  - Rest should be in Go 1.4.
   360  
   361  .image gocon-tokyo/contig-stack.png
   362  
   363  * But...
   364  
   365  - Problems are fixable.
   366  - It all keeps getting better with each release.
   367  
   368  * Go for everything
   369  
   370  - Since mid-2010, I prefer 90%-perfect Go for all my hacking:
   371  .image gocon-tokyo/changestats.png
   372  - Go is flexible, fun, readable
   373  - Go is fast (for computers & humans)
   374  - Go is good for working with others
   375  - Go for everything!
   376