Use the Go language to improve the performance of your Ruby app

Source: Internet
Author: User
This is a creation in Article, where the information may have evolved or changed.

In recent years, the go language has been quite compelling. It differs significantly from Ruby, with the advantages of go, such as low cost and easy-to-use concurrency, which allows us to find ways to apply to the processing tasks. reasons to use go. And will go into the details, I will provide the source code of my startup Project Firmapi.

What can you bring to the Ruby developer

1. Low-cost and easy-to-use concurrency

with go design, dozens of (or even thousands) of concurrent operations can be easily implemented.

Although the use of Ruby has long been able to handle threading, but its processing results far less than Go:ruby is using a green thread, (i.e. only one CPU is utilized), which is far from the channels way of go.

Brucelinxu
Translated 5 days ago

people top

top   Good translation!

2. Low memory overhead

A Go program compiles just a few M in size. They can efficiently utilize memory while maximizing the "squeeze" of machine performance. In the resource-dense type task Independent Gets the input and returns the result of the calculation In such cases, the performance of Golang is perfect. You can easily start multiple programs, they are awakened only when needed, and can also get very good performance.

3. Easy to deploy
the

Go program can be compiled into a small binary file within seconds. They can be easily deployed to your production server without any dependencies. Later on, I'll show you on  FIRMAPI how we deployed the go code to our servers.

Mud cow
translated 4 days ago

0 human top

top   translation is good Oh!

connect Go and Ruby

Already have a gem that has been published to make it possible. But I decided not to use it, because I thought (this gem) to let the Go program run in the background as a server and then communicate with the front-end Ruby program through Unix domain sockets is a little too much trouble, and finally I tried a straightforward approach:

is actually very simple: let the Go program return a J SON-formatted data and parse it in a Ruby program. In this way, we can use the Go program to accelerate all resource-intensive tasks. They will be compiled into binary files on the server. These go programs return a JSON-formatted data to the Ruby program each time it is called.

Mud cow
translated 4 days ago

0 human top

top   translation is good Oh!

1.  go Aspect

We expect the Go program to return a JSON and parse the normalized output with Ruby, which is an example.

Although there are many complex and useful programs with their own variables, the central idea will not change.

2.  ruby aspect

Ruby code can be streamlined to one line:

To stay organized, the Go program is placed in its own folder. This is easier to deploy. Then write a class that executes the corresponding go program to parse and respond to the JSON. In a production environment, binary packages are used to increase execution efficiency. The following is a possible class:

Uses the Method_missing class to let the new Go program run without changing the Ruby code. Developers just need to follow this rule and add new programs.

heavy blade no front
translated 3 days ago

0 people top

P class= "vote" > top   translation Good Oh!

how Organization Code?

I am in favor of including the go Code directly into your master repository. If the size and scope of the program you want to add is small, you can use source control to get some more. The main is ruby program and the Go program is not consistent. In the example, I saved the code to : my_app/go/program1/

deployment

With Go builder, go-generated binaries can be run either on-premises or on the product. The only problem is how to deploy these files: You can upload them to cloud storage (such as Amazon S3), then download them sequentially on the deployment environment, or upload them directly to your deployment environment. In our example, we add a custom task to  capistrano (poke here to see the script   the method of uploading to S3):

Heavy blade without front
translated 2 days ago

0 people top

top   Good translation!

Do not take any action on the server. For Go version, Gopath and so on, no dependency. It's perfect!

Conclusion

Learning go may give you the idea of solving problems in the current Ruby without causing additional setup headaches. I would particularly recommend looking at some of the better go routines and columns.

I look forward to getting feedback through this path! You can find me on Twitter: @antoinefink or e-mail antoine@finkelstein.fr.

No if
Translated 5 days ago

0 Person Top

top translation of good Oh!

All translations in this article are for learning and communication purposes only, please be sure to indicate the translator, source, and link to this article.
Our translation work in accordance with the CC agreement, if our work has violated your rights and interests, please contact us promptly

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.