How to measure performance – Java

Tags

, ,

How to know how much the app is consuming from memory? Where is the application bottleneck? How are the application Threads? How many classes are being loaded? How many instances are being created?

You can answer these questions by monitoring the JVM and using Profiling (this is the process of monitoring parameters at the JVM level, such as Method Execution, Thread Execution, Object Creation, and Garbage Collection).

In the post about testing tools (Let’s try something different: Testing Tools 01) it was possible to measure if the application tolerates X accesses, the response time of the application and etc. Now let’s measure HOW the JVM is reacting to this.

For this example, we will use VisualVM because it is free, easy to use and has a good amount of information, and we will also use the java-sample-project project. The use of VisualVM is very simple: when downloaded, you unzip it and execute the visualvm file inside bin folder. Follow the guidelines in the Java Sample Project to run the project. When VisualVM and the project are started, VisualVM should look like this:

Continue reading

Early Access: JUnit 5

Tags

, , ,

I was testing one of the news that are about to be released: JUnit 5. The first impression is that it has a lot of cool functionalities, such as parameterized tests, improved Exception assert, grouping tests by Tags and etc.

I created a branch of my java-sample-project project using some JUnit 5 features with Spring Boot and I will summarize just some of the features:

Parameterized Tests

  • It gives you the ability to run the same test with different parameters, coming from different sources: Inline Values (String, Integer, etc.), Enum, CSV, Methods…
  • In my project, I used @MethodSource to exemplify:

  • With this, the test will search for a method called createUsers that returns a Stream<Arguments>:

  • The expected parameters in my test method are: a User and an Integer, and in that Stream I’m passing both. The test will run first with userOne () and 1, and then with userTwo () and 2.

Exceptions Assert

  • With JUnit 4 it was possible to test exceptions, both with @Test(expected=…) and Exception Rule (ExpectedException). This last one could still validate the exception message. But I believe nothing compares to this assertThrows:

Continue reading

Let’s try something different: Testing Tools 01

Tags

, , , ,

For testing tools and some other examples, I recommend one of these projects: python-sample-project ou java-sample-project, pretty simple projects for testing easily and quick.

Locust

  • A simple load testing tool, but powerful. You write Python code on tests, so the flexibility is a little bigger.
  • Prerequisites:
    • Python 2.7.4+ or 3.3+

Pros:

  • Some flexibility on tests
  • Easy to Install
  • Easy to Configure
  • Easy to Use
  • Multiplataform

Cons:

  • Although showing the main information, it could show more useful information and / or charts
  • The test never stops unless you click to
  • Tests HTTP calls but doesn’t test flows as a real user would do in a browser

Result Example:

locustio

SOURCE: http://locust.io/

Link: http://locust.io/

Httperf

  • It’s a simple but also powerful performance testing tool.

Pros:

  • Easy to Install
  • Easy to Use
  • Great amount of info
  • Great amount of customization of calls
  • Can limit the total of requests

Cons:

  • Linux Only
  • Tests HTTP calls but doesn’t test flows as a real user would do in a browser (but it is not what it proposes to do)

Result Example:

httperf

Source: http://www.labs.hpe.com/research/linux/httperf/httperf-man-0.9.pdf

Links: https://github.com/httperf/httperf and https://linux.die.net/man/1/httperf

In my list of tools, the next to be tested is Multi-Mechanize. If you have any suggestions, send me.

Why do you do what you do?

Tags

, ,

It seems like a simple question, but you need to think hard about why we work with what we work with. As a developer, I see a lot of people saying they program because of the money. Others say they program because of the number of jobs they have and so on.

Why am I asking you this? After all, I myself entered the programming area because I did not go through electrical engineering and Computer Science was one of the few courses where I was not very life-threatening (ironically, it is one of the most stressful ones to me, which apparently is not very good for health).

The first thing to be a good professional, regardless of the area, is to love what you do. When you love what you do, you dedicate yourself, you study, you want to improve, because you love what you do.

“Choose a job you love, and you will never have to work a day in your life.” (Confucius)

Another point I would like to highlight is: seek professional happiness. You may love your profession but work in a place that does not give you the satisfaction you need to perform well. Maybe, problems with the boss, problems with the company’s culture, maybe even salary. We know that there is no perfect company, but if you are not happy, have talked and not resolved, do not be afraid to seek your happiness.

The second last point is: do not be afraid to change, be afraid to stand still. It has happened that I am doing what I like, in a place I like and not evolving, and I do not mean job levels or positions in the company, I mean knowledge, professional growth, knowing more and more. Some people like routine and always doing the same thing, but the fact that you are not evolving has to bother you. You love what you do, you have to feel like learning more and more.

The last and not least point is: always do your best. Depending on the work area, the chance that you will work with someone who has worked with you is very large. Your professional image tells a lot about you. Do not be known as the person who “even worked, but …”. Rest assured that in all your work you have given your best and do not be afraid to be happy.

IDE – Visual Studio Code

Tags

Some people ask me which IDEs I use to develop. Usually I used to use an IDE for each language: Eclipse for Java, PyCharm for Python, and so on… I tried to see a generic “IDE” (like a code editor with plugins) as Sublime and Atom. I always read stories that said they are good but heavy.

I tested Sublime, even liked it, but I thought that wouldn’t worth to buy or keep using. I downloaded Atom and the size already scared me: on that time was almost 130 MB or something close to that. I didn’t even install Atom when I heard a friend recommeding me Visual Studio Code. I got curious and I downloaded.

I had a surprise right away: at the time, 40 MB to download. By installing, I already liked the interface, the ease and the native support for Git. I used and enjoyed it, it did not take up much memory and I got carried away. I started to use other languages that I usually program and I was downloading plugins. I accidentally press a Hotkey I used in Eclipse and suddenly open a terminal inside the VS Code. That’s it. It was all I needed.

Continue reading

DevOps

Tags

, , , , , ,

What it is?

DevOps is an integration culture between Development and Operations, aiming that both participate together on the entire software lifecycle (Software Development Life Cycle – SDLC). Some of the main focuses of DevOps: better-quality software, collaboration between Dev and Ops and continuous improvement.

Directly Associated Practices

  • Cloud Computing (AWS, Azure, Google Cloud)
  • Infrastructure as a Code (Chef, Puppet, Ansible, SaltStack)
  • Automated Tests
  • Builds and Continuous Integration (Jenkins, Bamboo, CircleCI)
  • Continuous Delivery

Indirectly Associated Practices

Some practices that end up also being associated with DevOps:

  • Containerization (Docker, RKT)
  • Continuous Deployment

What DevOps is NOT?

  • A tool or just the practices.
  • Just automation.
  • Job Title.
  • Just about Dev and Ops.

Why to adopt DevOps?

  • Continuous and quick Feedback
  • Better quality
  • More reliable releases
  • Shorter TTM (Time-To-Market)
  • Better collaboration between teams
  • Continuous Learning
  • Continuous Improvement

More Knowledge

Free Course about DevOps: https://www.udacity.com/course/intro-to-devops–ud611
Podcast (BR): https://blog.lambda3.com.br/2016/10/podcast-12-devops/
Podcast (EN): https://www.arresteddevops.com/what-is-devops/
Reading: http://www.agileweboperations.com/what-devops-is-not
Reading: http://gutocarvalho.net/octopress/2013/03/16/o-que-e-um-devops-afinal/
Book: http://shop.oreilly.com/product/0636920039846.do

Programmer Utilities – Java Tools 01

Tags

,

Spring Loaded

Main Function: Refresh Java code without restarting server.

Similar: JRebel.

URL: https://github.com/spring-projects/spring-loaded

  • To use Spring Loaded, you have to download the jar and add the following parameters on JVM:
-Djavaagent:ABSOLUTE_PATH/springloaded-1.2.5.RELEASE.jar -noverify
  • On the servers below, the parameters ALSO must be included:
    • JBOSS
-Djboss.modules.system.pkgs=org.jboss.byteman,org.jboss.logmanager,org.springsource
-Djava.util.logging.manager=org.jboss.logmanager.LogManager 
-Xbootclasspath/p:${JBOSS_HOME}/modules/org/jboss/logmanager/main/jboss-logmanager-1.2.0.GA.jar 
-Xbootclasspath/p:${JBOSS_HOME}/modules/org/jboss/logmanager/log4j/main/jboss-logmanager-log4j-1.0.0.GA.jar 
-Xbootclasspath/p:${JBOSS_HOME}/modules/org/apache/log4j/main/log4j-1.2.16.jar
  • Wildfly
-Djboss.modules.system.pkgs=org.jboss.byteman,org.springsource

After that, you only need to start the server in Debug Mode and any change on Java Code that is not on method definition or new method/class, you won’t need to restart. It’s recommended to disable the server’s Hot Deploy (Never publish automatically).

PODAM

Main Function: Fill a class (and its dependencies) with random data.

URL: http://devopsfolks.github.io/podam/

Main Functionalities: In addition to being able to fill a class, you can define strategies to generate your data, it supports Bean Validation, generating data for example: Numbers between 3 and 5 (@Min and @Max), and more. Continue reading

Tiers vs Layers

Tags

, ,

Tiers and Layers, in portuguese, are translated to the same word: “camadas”, so, unfortunately there’s no way to understand what they really means, because are two different things and very important. Regardless of language translation, I intend to explain the difference between them on this post.

Tiers

  • Physical separations between parts of the system.
  • It envolves system components that runs or could easily run on separated machines.
  • Tiers Example: Web Server, Database, Distributed Cache, Application Server, etc.

Layers

  • Logical separations between parts of the system.
  • Layers Example: MVC, DDD, etc.
  • Focus on organizing your code.

Layers help decrease coupling and improve separation of responsibilities for better maintenance, evolution and organization of the system.

2 TIERS x 3 TIERS x N-TIERS

– 2 TIERS

2-tiers

Example: Clients accessing a database with business logic in stored procedures.

Advantages: 

  • Security
  • Performance

Disadvantages: 

  • Database dependency
  • Difficulty of integration
  • Low separation of responsibilities
  • Low maintainability
  • Point of failure
  • Difficulty keeping all clients up to date

– 3 TIERS

3_tiers

Example: The remote client, the Web Server and the database.

P.S.: In this case, it loses the meaning of business logic to stay in Stored Procedures. Business logic would now be run in the middle tier (business tier).

Advantages:

  • Ease of updating
  • Ease of integration
  • Separation of responsabilities
  • Security
  • Confiability
  • Easy to keep all clients up to date
  • Better maintainability

Disadvantages:

  • Points of failure
  • Less performance

– N-TIERS

3-Tiers variation. Usually 3-tiers with additional tiers as replication in clusters, load balancers and other tiers. It is also common to say that 3-Tiers are N-Tiers where N is equal to 3.

Attention to adding new tiers:

  • It might impact performance
  • Significant improvement in scalability
  • Improvement in disponibility
  • It might impact complexity
  • It can make it difficult to manage and maintain the entire infrastructure

That’s it folks, I hope you liked it.

References: Introdução À Arquitetura e Design de Software, https://www.casadocodigo.com.br/products/livro-arquitetura-java

Programmer Utilities – Podcasts 01

Tags

,

Talk Python To Me

  • As the name says, a podcast about python and related technologies.

URL: https://talkpython.fm/

5 Minutes of Javascript

  • Podcast about Javascript and its news.

URL: https://fivejs.codeschool.com/episodes

JsJabber

  • Podcast about Javascript and good practices of Javascript and other news, such as related programming languages.

URL: https://devchat.tv/js-jabber

Javascript Air

  • Podcast about Javascript and good practices of Javascript and its news.

URL: http://javascriptair.podbean.com/

Appendix: Extras

  • In addition to my favorites above, here it’s a list of other podcasts for you to decide which ones you like the most (Portuguese and English).

URL: http://ogilvieira.com.br/awesome-podcasts-br/#/

Beyond The Basics – Servlets, JSP and HTML

Tags

, ,

Servlets and JSPs were important for long time, but some concepts are very important and curious and may not gain the proper attention. How a JSP page turns into an HTML page? How can we work directly with the HTML instead of JSP (like the Thymeleaf)?

Remembering…

  • JSP

Java Server Pages, that are template engines. On it, it’s possible to write Java code either directly (scriptlets) and with JSTL / taglibs, and you can get parameters / objects passed through a Servlet.

  • Servlets

Java classes that are responsible for dealing with requests from Web clients, such as the browsers.

  • Web Container (Servlet Container)

It is a component of a web server that interacts with Java Servlets. It is the container that delivers the servlet the request and the HTTP response, and calls servlet methods (such as doPost or doGet).

How JSP turns into HTML with filled data?

When a JSP is requested, the Web Server uses a JSP compiler and converts the JSP into a Servlet that implements the interface javax.servlet.jsp.JspPage.

O arquivo JSP é compilado somente quando a página é requisitada pela primeira vez ou quando o arquivo JSP é alterado, ou seja, o Servlet gerado a partir do JSP é reutilizado, fazendo as próximas chamadas serem mais rápidas.

The JSP file is compiled only when the page is first requested or when the JSP file is changed, i.e., the Servlet generated from the JSP is reused, making the next calls faster.

But how so? The Web Server that transforms the JSP? 

That’s right. The Web Server transforms the JSP into a Servlet.

But what about my Servlet? And what’s that getRequestDispatcher? Continue reading