Recently I had to send some stats from a Finagle based application (Finagle collect and expose some metrics automatically) to the same Graphite server, so I had tried the same approach using the Metrics library, and as a result, I ended up doing a finagle module called finagle-metrics.
So let’s see how to use it! :)
First things first. So, let’s install the finagle-metrics locally. To do that, just run:
After that you should see something like this output:
Okay, the finagle-metris is now installed locally, so from now on we can add it as a dependency to our finagle application. We need to create some folders and files, so let’s do that:
Then I’m going to add the following content to build.sbt:
And finally, let’s create our finagle application. I’m gonna add the following content to /src/main/scala/App.scala:
Note that I used the ConsoleReporter to report the Codahale’s metrics to the console every five seconds.
Also, note that I didn’t need to do anything related to the finagle-metrics, I just needed to define a location (Reporter) to where the Codahale metrics will be sent, but the metrics themselves were sent automatically (Thanks Finagle for that). :)
To run our example, just execute the following command and wait a few seconds to see the metrics being displayed on the console:
Click here to see more about the finagle-metrics library.
Functions like map and reduce are very useful, we can use them to extract values from lists. Nowadays these functions are available in the most recent browsers, but have you ever thought about how to implement them?
At first we’re creating a function called each. We’ll use it to iterate over a list, apply a function and then generate an accumulator. If done it correctly, we will be able to abstract out complex parts of our algorithm, replace it with a function call and keep code condensed and readable.
So let’s see the function:
Okay, now we can create our map function. Basically a map function is a function that applies a given function to each element of a list and then returning another list of results.
It’s our map function:
See, it’s not a big deal. We use the each function to iterate over the list and replace each list value by the result of transform function. So how can we use it? Let’s transform (multiply each value by 2) a simple array of numbers.
And now the last one function called reduce. Different from map function, this one returns only one value with an initial value predefined that is the result of a combine function executed recursively over each element of the list. See the following function:
As an usage example, let’s think up a shopping cart with some items. We’ll need to calculate the total order to show it up at the checkout page.
As can be seen, functions like map and reduce are great to transform and/or combine lists, and functional programming is good to abstract out complex algorithms.
It’s a very simple function, isn’t it? :)
But you in an inspired day, decide to create a way to abstract the code above to something like a template method, thus you could use that at other functions. Let’s see our new function:
Now we have our cool template function, but let’s wonder ourselves if we could have some performance issues adding that new function. What do you think about it?
Yeah, probably you’re thinking about a way to measure our new function against the first one, and that’s exactly what we’re going to do.
To do that, we can use these two functions console.time() and console.timeEnd() to measure the time taken by a function execution. The function console.time() takes a timer name, and console.timeEnd() must take the same timer name, then it’ll report on the execution time since the timer started. Let’s use them to measure our two functions:
And the output is:
Wow, the second function is about 7 times slower than the first one, and it would probably be a problem in a real application.
Escrever um livro técnico foi um grande desafio pois eu já tinha publicado artigos técnicos mas nunca algo na dimensão de um livro, e imagino que por isso eu achei fantástico escrevê-lo. Também fiquei muito feliz com o resultado final do livro e espero que gostem do livro.
Saber usar a melhor ferramenta para cada problema é determinante para qualquer pessoa ligada à área de tecnologia e atualmente com o desenvolvimento de novos bancos de dados, as opções para essa área aumentaram bastante, trazendo muito mais poder às aplicações.
Nesse livro, Rodrigo Lazoti vai te mostrar porque trabalhar com o Redis e bancos de dados chave/valor podem trazer enormes ganhos de performance para sua aplicação, além de ser a ferramenta ideal para diversos sistemas.
Você vai aprender a trabalhar com estruturas clássicas e modernas de dados e armazenamento, filas, listas, conjuntos, além da configurações de mecanismos de publish e subscribe e claro, como usar todo o poder da API do Redis.
Trabalhar com o pessoal da editora Casa do Código foi uma ótima escolha na minha opinião, pois o pessoal te oferece todo o apoio e ajuda necessária durante o processo de escrita do livro. Além do fato de ser uma editora amplamente conhecida e reconhecida pelos desenvolvedores e pessoas ligadas a área desenvolvimento de software em todo o Brasil.
Basta acessa o link:
My emacs configuration is very simple and it was based on Emacs Prelude. My setup can be found in my repo at https://github.com/rlazoti/emacs.d and you also can see there a list with my useful shortcuts that I use constantly.
If you wish to install it, just type:
1 git clone https://github.com/rlazoti/emacs.d.git ~/.emacs.d
There are many ways to install Emacs, you could install it from the sources or maybe using a package manager. I’m going to show the way that worked better for me. ;) Let’s see it…
I installed on the Mac OS a ‘mac port’ of emacs 24. I did it with Homebrew but it’s possible to download a version directly of here. To install with Homebrew do:
1 brew tap railwaycat/emacsmacport
1 brew install emacs-mac
That’s it! It should be ready to use.
Emacs 24 included a package manager called package.el and it already include a repository called ELPA, but it’s possible to use multiple repositories. In fact I use just one more repository called MELPA.
These are the main packages I use: