using lazy val http for async so can be overridden #279

Merged
merged 2 commits into from Sep 29, 2014

Projects

None yet

2 participants

@rubbish
Contributor
rubbish commented Sep 29, 2014

We're overriding the dispatch.Http so that we can give it different configuration (request/connection timeouts, user agents, etc). However, we noticed that we were generating many threads from many different netty NioWorkers. Looking into it more, it turns out each AsyncHttpClientConfig.Builder spawns a thread pool of these. And looking at our heap dumps, we found that there are many AsyncHttpClientConfig.Builders within the heap.

Anyways, we found out that due to the scala trait initialization order, the scalaxb.DispatchHttpClient was always initializing a new Http even though we were overriding it. So by making it a lazy val, we can safely override it without worrying about it getting initialized.

@eed3si9n
Owner

Could you add a comment to the effect in the code since the change is too subtle and I don't want that to be rolled back by mistake in the future. It could be something like:

// Keep it lazy. See https://github.com/eed3si9n/scalaxb/pull/279
@eed3si9n eed3si9n added the bug label Sep 29, 2014
@rubbish
Contributor
rubbish commented Sep 29, 2014

@eed3si9n Added.

@eed3si9n eed3si9n merged commit abc5069 into eed3si9n:master Sep 29, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment