Improve performance and make JWT auth non-blocking#59
Conversation
Summary of ChangesHello @tekrajchhetri, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly enhances the performance and scalability of the JWT authentication system by transforming blocking operations into non-blocking asynchronous calls. By leveraging Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request is a great step forward in making the JWT authentication logic fully non-blocking. The use of asyncio.to_thread for CPU-bound tasks like password hashing is correctly implemented, and the switch to an async with context manager for database connections significantly improves resource management. My review focuses on a potential race condition in the user registration flow and suggests adding return type hints to enhance code clarity and maintainability. Overall, these are excellent changes that improve the application's performance and robustness.
…o support scalability
|
Hi @tekrajchhetri - do I understand correctly, that you believe that the issues with content loading was due to the authentications issues. And since query and ml services used the same method, it was affecting both. Thank you for creating plots. These plots are after your changes, correct? It would be nice to see how your changes have improved the times, do you have the plots before your changes? Also, I understand that you run your testing/plotting functions twice, for different |
|
There's a script that I ran for this that you can look at Regarding the problem, I have created an issue sensein/brainkb-ui#101. To answer your question, its not authentication issue but the database issue--connection was not released and was problematic when there're more connections--that was causing the authentication problem. |
Yes, I saw the script, but if you can provide the arguments you used to run it would allow to comapre. Also, I asked if by any chance you run the scripts before and after changes? Another question was if it makes sense to test
Yes, I saw the issue about loading the data, but I understand that you found out that the process of the authentication was responsible for it (not the query service) |
|
yes, but the test result includes both Steps to test:
|
|
@djarecka any update on this? |
|
Hi @tekrajchhetri - I really try to understand the meaning and importance of the statistics you plotted, so please answer the questions I've been asking (and if the question is not clear, let me know, I can clarify):
|
|
@djarecka I said, I used the default configuration parameters that's in the script. I am not sure why you are still asking for arguments. Did you check the code to see what are the default arguments, if not please check the configuration parameters here -- ?Regarding how this testing is useful? You did see the issue with the current website. It tests under load if the login works properly with no database issue. And no I did not ran the test code before, only after fix. |
just to clarify, when you mean that you run "the default arguments" and "Update test file accordingly to correct API endpoints", you mean the
You can merge this PR, but in the future I would like us to think more about what we call a "test". If someone fixes an issue and adds a test, I would expect that the test could be (and was) used to show the difference before and after the fix. I do understand that testing UI is not that easy, and we should add more test in the future. Because I want to work on this, I tried to understand the importance of the plots, but we can come back to this later. |
|
@djarecka I am merging this request. Just to clarify, it's not UI testing. Also, the URL would be Yes, we can discuss about testing and other things in the meeting. |
yes, I know. I was writing this about BrainKB in general.
I'm glad we agree on the argument you used. I would just ask for the future, if we are adding plots to PR with any kind of metrics, we simply add the commands that were used to generate them and the description. |
This pull requests updates the code to make it async/non-blocking to address the following issue sensein/brainkb-ui#101.
Test System
Apple M3 Pro/36GB RAM/12 Cores
MLService Test
Total requests: 5000 with 100 concurrent requests
Success (2xx): 4982 (99.64%)
Failures: 18 (0.36%)
Latency ms: min=19.83 avg=3533.93 max=10118.82 p50=3510.18 p90=4259.24 p95=4506.85 p99=5305.97
Status counts:
200: 4982
NO_STATUS: 18
Test results:




Queryservice
Total requests: 5000
Success (2xx): 5000 (100.00%)
Failures: 0 (0.00%)
Latency ms: min=655.10 avg=3402.47 max=8468.60 p50=3358.82 p90=4232.98 p95=4568.08 p99=5212.95
Test results:



