cdancy / bitbucket-rest

Java client, built on top of jclouds, for working with Bitbucket's REST API
Apache License 2.0
76 stars 57 forks source link

Improve the performance of creating/building a client instance #323

Open tdauth opened 2 years ago

tdauth commented 2 years ago

Expected Behavior

Building a client should be a fast operation since I do not expect anything to be done.

Current Behavior

The operation

com.cdancy.bitbucket.rest.BitbucketClient$Builder.build()

seems to be really slow.

Context

My application retrieves data from multiple Bitbucket repositories creating the client multiple times which apparently was the wrong approach since it is for one endpoint only. However, I am able to close the client so to write clean code I create a new client and close it afterwards.

Steps to Reproduce (for bugs)

Create many clients.

Your Environment

Anywhere I guess.

cdancy commented 2 years ago

multiple Bitbucket repositories

@tdauth when you say "multiple Bitbucket repositories" do you mean the same Bitbucket instance but against multiple repos within that instance or do you mean quite literally multiple Bitbucket instances you're connecting to? If the former you can just create 1 client as it's thread safe and can be shared amongst many requests/etc.

tdauth commented 2 years ago

Yes I can create only 1 but for the first scenario I would need many clients. I am just wondering why it is so slow.

cdancy commented 2 years ago

@tdauth how slow are we talking? Can you provide measureable numbers? I've never created many clients at once before but underneath it's using the jclouds framework which itself can tend to be heavy and so may be doing a lot of setup.

tdauth commented 2 years ago

Well my test took 18 minutes and then only like 4 minutes after using only one client per endpoint (using two endpoints). I created a client per repository and sometimes also per file. It would be nice to at least document it in the README or somewhere to not write your code like I did or even better to improve the performance. Even when you are always using the same Bitbucket endpoint you might want to clean up the bitbucket client with close afterwards. I am not sure when to close the client now when using two static client instances.

cdancy commented 2 years ago

It would be nice to at least document it in the README or somewhere to not write your code like I did or even better to improve the performance.

This to me is just general knowledge when working with java. Unless documentation states otherwise you can use a given client across the board.

I am not sure when to close the client now when using two static client instances.

That would be up to you the developer to implement. You could so as part of a shutdownHook or when your object is destroyed or any other number of means. It all depends on your setup and application and what you want to do.