creature

Global history is unfolding right now. You have a chance to be an active part of it, help Ukraine!

5 Ways To Improve Application Performance

Ihor Kosandyak Lead Software Engineer | Expertise : Java, PropTech, Marketplaces, System integrations Linkedin
Share

9 Aug, 2019 · 4 min read

5 Ways To Improve Application Performance

It’s not that easy to create fast, easy, and smooth applications. You need to be aware of tons of cases that will happen to your app in the future as your users’ amount grow. Especially, this is true for IoT application development, which still remains a complex, time-consuming, and challenging activity despite much progress in this niche.

That’s why you need to think of tools that will help your software to be modern, fast-responding, and scaleable. Here we will speak about the Top 5 Ways of Performance Improvements of your Spring Boot Application. Let’s get started!

1. CACHING

Don’t be afraid of caching your data. HTTP calls are expensive operations. It takes time for user to: Make request from Web Browser → Get your API reached → Backend API handles request, and makes another one to the Data Source to pull requested info → Data returns back from the database to backend API → Data is then handled, operated on and returned to your end user. OUCH! It takes for ever.

Imagine you have 4K requests at the same time that will go through all of the above steps for data accessing. They are quite expensive and painful for the application and database.

Here you can make something that could decrease waiting/working time for your users by enabling caching in your application. Instead of hitting all the time the data source for requested info — you can cache the response data from the previous request for that particular information, and give it back to users without hitting the database. Such scenario can boost requests in dozens of times. For example, without caching request may take for 700 milliseconds. While it can around 40–50 milliseconds, when using cache.

The bottlenecks here — is to not overload your application cache. Don’t cache everything! And don’t forget to flush your cache at some points. As well as updating the cache, so it will always replicate the data that is stored in you database. Be careful here!

For the cache provider you can choose whatever you prefer, since currently there are lots of options available. It can be either Redis, or Hazelcast, or EhCache, etc. Just pick the most loved one, and be happy!

2. STRINGBUILDER

What you always do in your app is String concatenation. This a very common operation. But an expensive one too. Every time when += is used — it creates new String object and allocates memory for it. Imagine: you have a list of 10K elements, you need to go through each element, and add some string value to the existing string of the element. Well, at least 10K new string objects will be created and stored in memory for that simple enough operation. Of course — this is sad.

Use the StringBuilder instead. It is much more efficient than String concatenation. And it doesn’t create new object each time when his append method is called. No new objects created — no memory is loaded!

3. BE CAREFUL WITH REGULAR EXPRESSIONS

Regular expressions by its nature — are extremely expensive for the application. They take significant amount of memory to be processed. So avoid using regular expressions in streams, loops, and other operations that will trigger regular expression many times.

Also we are not talking about just custom regular expressions that we create for example for email or credit card validation. Java String class methods use regular expressions under the hood. For example String.matches(str0), String.replaceAll(str0). So, be aware of this!

4. SCALE OUT!

Every kind of hardware has its limitation. If you improve your app hardware by adding more RAM for example as your app growth — some day you may reach this limit, so the power of that hardware will not be enough for your application demands. So scaling up will be impossible! Here you will decide to SCALE OUT!

More instances you have behind a load balancer — more chances you have that your app will be 100% time available for your users. This is important to grow your business!

5. RIGHT DATABASE

It is very important to choose the data source that will fit your application needs as best as possible. Currently there are tons of databases you choose from for your app.

Have a long time meeting with your team and business developer to imagine and visualize your system in one year after development started. Take a look if the entities in database are complex and have tight relations. Decide what is the better option for in terms of data source. SQL or NoSQL one? Or another? Each of the database has own advantages and disadvantages. Some are extremely fast in writing data. Some — in reading. Some are good to go with if you don’t have lots of nested objects inside database entity, others are good to go if your models going to have dozens of relations with entities from different tables. So database picking might be a key decision for the project. So don’t be afraid of spending much time on this. It worth it!

So if you follow these simple steps during your app development — it is more likely that you won’t have big performance problems with an increased load of your server 🙂

Thank you for reading! If you liked that — don’t forget to put thumbs up on the left side of your screen and help others to find this article on a WEB!

Cheers!

No Article rating
0 Reviews
Was this article helpful? Please rate this article to give us valuable insights for our improvements.
  1. Wow
  2. hidden
  3. hidden
  4. hidden
  5. Pff

#Java

Secure your Spring Boot API with JSON Web Tokens

If you are reading this article I assume you are a bit familiar with Spring Boot and building API using it. Because the main purpose of this article is to show you a simple way how to make your API more secured.

Ihor Sokolyk

7 Jun, 2021 · 6 min read

Spring Cloud Gateway security with JWT

There is a clear understanding that everything that is exposed to the Internet should be secured. Especially when you create software and work with sensitive user data, such as emails, phone numbers, addresses, credit cards, etc. Here we will go through securing API Gateway with Json Web Tokens(JWT). As far as you probably know Spring […]

Ihor Kosandyak

26 Feb, 2021 · 4 min read

Two-Factor Authentication with Java and Google Authenticator

I am more than sure that each of you have at least one account with enabled Two-Factor Authentication (2FA). But if you are still unfamiliar with 2FA I’ll give you some general explanation. It’s a second step in login sequence that asks you to enter 6-digits code sent to you by email, text message or […]

Ihor Sokolyk

26 Sep, 2019 · 4 min read