Slide 1

Slide 1 text

Interoperability with Go GoLab 2017 @ Italy
 Matias Insaurralde

Slide 2

Slide 2 text

About me - I work on Tyk (tyk.io), an open source API gateway written in Go.
 - I’m 22 years old and I live in Paraguay, a small country in the heart of South America. - Wrote my first program when I was 10 years old.
 - I like pasta :)

Slide 3

Slide 3 text

Request flow 
 API Gateway Middleware HTTP
 Request Upstream API Middleware …

Slide 4

Slide 4 text

The middleware chain

Slide 5

Slide 5 text

Custom middleware?

Slide 6

Slide 6 text

A first approach: JS - Using Otto, a JS interpreter, by Robert Krimen:

Slide 7

Slide 7 text

Looking at cgo - How to make it easier to integrate new language runtimes?
 - A lot of language runtimes are embeddable and have nice APIs for that.
 - In-process request passing. - “Mapping” our http.Request to C structs (and passing them) makes sense, but it’s hard to maintain, we also need to pass session objects (lot of fields and nested structures). - We decided to use Protocol Buffers, it has a significant overhead but makes it maintainable.

Slide 8

Slide 8 text

cgo-based middleware 
 
 Python runtime Python middleware 
 API Gateway HTTP
 Request Upstream API

Slide 9

Slide 9 text

Let’s try Python! - CPython is easy to embed. - We combined this with Cython-generated modules (loaded with cgo!). - A few disadvantages…

Slide 10

Slide 10 text

- This is a simple Python middleware: Let’s try Python!

Slide 11

Slide 11 text

LuaJIT - We did a LuaJIT integration.
 - No official Protocol Buffers modules for Lua :(


Slide 12

Slide 12 text

LuaJIT

Slide 13

Slide 13 text

A few notes - Serialization made things easier, but involves copying data structures. We’re in the process of optimizing this.
 - We did a lot of benchmarks, LuaJIT is able to handle a lot more requests per second than the rest of the embedded runtimes.
 - I find the Protocol Buffers + cgo combination very powerful.
 - Go 1.8 “plugins” will give us a lot of possibilities.

Slide 14

Slide 14 text

- Last year I wrote a quick PoC called “go-dotnet”.
 - .NET has a CLR “Hosting API”, I didn’t find enough documentation about it.
 - The PoC uses the CLR Hosting API, and it does a very simple thing (from Go): loads an assembly file (DLL) and calls a .NET function. go-dotnet

Slide 15

Slide 15 text

go-dotnet

Slide 16

Slide 16 text

go-dotnet

Slide 17

Slide 17 text

go-dotnet - An idea for code generation:

Slide 18

Slide 18 text

- You may find the code here:
 http://tinyurl.com/go-dotnet
 - I’m working on the code generation approach, and would like to turn the PoC into an useful package. - Interesting things to try: serve ASP.NET apps with net/ http :p go-dotnet

Slide 19

Slide 19 text

The end Thanks!
 
 You may find me here:
 
 Github: https://github.com/matiasinsaurralde
 Twitter: https://twitter.com/matias_baruch
 E-mail: [email protected]