bitbucket-rest icon indicating copy to clipboard operation
bitbucket-rest copied to clipboard

Improve the performance of creating/building a client instance

Open tdauth opened this issue 3 years ago • 5 comments

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.

tdauth avatar Jan 20 '22 17:01 tdauth

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.

cdancy avatar Jan 20 '22 17:01 cdancy

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.

tdauth avatar Jan 20 '22 17:01 tdauth

@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.

cdancy avatar Jan 20 '22 17:01 cdancy

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.

tdauth avatar Jan 20 '22 18:01 tdauth

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.

cdancy avatar Jan 20 '22 21:01 cdancy