-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cookiejar optimization #1708
Cookiejar optimization #1708
Conversation
@slandelle Please let me know if this looks good. Thanks |
client/src/main/java/org/asynchttpclient/cookie/ThreadSafeCookieStore.java
Outdated
Show resolved
Hide resolved
Nice work. However, I have some concerns regarding CookieStore handling its own scheduling. For example, someone spawning multiple AHC instances with different configs would spawning multiple threads for nothing. I think it would be better to use AHC's HashedWheelTimer instance for scheduling. |
Thanks for the feedback. Let me change code to use HashedWheelTimer. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I'm not happy with the current design. I'm still convinced Timer and CookieStore should be isolated.
client/src/main/java/org/asynchttpclient/DefaultAsyncHttpClientConfig.java
Outdated
Show resolved
Hide resolved
client/src/main/java/org/asynchttpclient/cookie/ThreadSafeCookieStore.java
Outdated
Show resolved
Hide resolved
…Task to evict expired cookies.
0aeaf92
to
a0c0365
Compare
@slandelle Please let me know what you think. Thanks. |
client/src/main/java/org/asynchttpclient/cookie/ThreadSafeCookieStore.java
Outdated
Show resolved
Hide resolved
client/src/main/java/org/asynchttpclient/cookie/ThreadSafeCookieStore.java
Outdated
Show resolved
Hide resolved
client/src/main/java/org/asynchttpclient/cookie/ThreadSafeCookieStore.java
Outdated
Show resolved
Hide resolved
client/src/main/java/org/asynchttpclient/cookie/ThreadSafeCookieStore.java
Outdated
Show resolved
Hide resolved
Looking good. Now, I think the last missing piece is to handle CookieStore sharing from multiple AHC instances. Currently, if we share a CookieStore, we'll end up scheduling cleaning multiple times, and never stop scheduling. I suggest we use an AtomicInteger to keep track of AHC instance a given CookieStore is configured on, only start scheduling when starting first client and only stop scheduling when closing last one. WDYT? |
Sounds good. Will start working on that. |
Thanks a lot for your great work! |
@slandelle I've a few questions that I would like to get your opinion (Both cases assume sharing cookie store).
I'm assuming that you made the comment above assuming that user shares a timer? Please correct me if my assumption is wrong. If user does not share timer, then I guess we have to schedule eviction task on each timer. Also a follow up question regarding creating new Timer for each AHC instance. I feel like we could share the same Timer for multiple AHC's, but I think there might be a strong reason on why not too. But just curios to know. Timer starts to emit error logs when the count is greater that 64. |
I've made some changes assuming you are talking about shared netty timer. Please let me know how this looks. Happy to implement any of your suggestions. I do not know if sharing netty timer across all AHC instances is useful or harms the overall performance (because all tasks share same timer). But if you'd like to see sharing a single netty timer (instead of creating a new one for each instance) in-case a user does not provide one, I can make that change as well. |
Yes
Let's do that
Could you please share the error logs? |
I've personally have not created too many instances to see this message. But I was checking through source code of HasedWheelTimer and found that it spits out an error log when number of instances are greater than 64. Logs like this:
The changes are made according to your expectation. Please let me know otherwise. I can make the change to share netty timer if you are interested. |
@sivaalli Thanks! |
Closes: #1580
Changes: