Skip to content
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

Slow performance #225

Closed
gastonmorixe opened this issue Mar 23, 2023 · 10 comments
Closed

Slow performance #225

gastonmorixe opened this issue Mar 23, 2023 · 10 comments

Comments

@gastonmorixe
Copy link

Describe the bug

I am not sure why yet but our requests are taking like between 5 to 15 seconds most times.

I tried to log using httplog gem and it stops after the connecting step, after that for like 10 seconds goes fast.

May it be related to httparty gem using Net::HTTP? I think it doesn't support http2 nor keep-alives

CleanShot 2023-03-23 at 03 45 43@2x

@jtoy
Copy link

jtoy commented Mar 23, 2023

I see many requests time out but looking at the API status page, it shows up as fine. I also tested with python and the code takes a while to run, but it doesn't error with a timeout at least.

@jtoy
Copy link

jtoy commented Mar 23, 2023

FYI I see a new version came out to help address this issue: https://github.com/alexrudall/ruby-openai/releases/tag/v3.6.0

@gastonmorixe
Copy link
Author

@jtoy v3.6 didn't change much. I did some research and tests and it seems to me that a big part of the slow performance is due to HTTParty's Net::HTTP usage.

Quickly hacking HTTParty I enabled keep-alive to persist the connection and it improved by around ~50%.

I think moving to another gem that doesn't rely on Net::HTTP and enabling streaming is key to unlock good performance.

@bf4
Copy link

bf4 commented Apr 3, 2023

I think the OpenAI API itself is unstable. But the idea of using net-http-persistent style keep-alive when available or via adapters sounds it could be a good approach as well. Probably part of #189

@gastonmorixe
Copy link
Author

I agree

@deikka
Copy link

deikka commented Apr 22, 2023

@jtoy v3.6 didn't change much. I did some research and tests and it seems to me that a big part of the slow performance is due to HTTParty's Net::HTTP usage.

Quickly hacking HTTParty I enabled keep-alive to persist the connection and it improved by around ~50%.

I think moving to another gem that doesn't rely on Net::HTTP and enabling streaming is key to unlock good performance.

How did you hacked HTTParty? Thanks.

@dep
Copy link

dep commented Apr 23, 2023

I think moving to another gem that doesn't rely on Net::HTTP and enabling streaming is key to unlock good performance.

Does such a gem even exist though?

@alexrudall
Copy link
Owner

#234 adds streaming with Faraday - final reviews much appreciated 👍

@panozzaj
Copy link

panozzaj commented Sep 29, 2023

I looked and #234 is now merged. We may be able to close this issue if the performance issues mentioned here are now fixed with the change to Faraday. (I only note this as a new user of this library who was checking issues and saw this since performance seems important.)

@jtoy
Copy link

jtoy commented Sep 29, 2023

One more comment, I’m not sure which is better, it I’ve personally moved to http.rb for all networking requests. I’m not sure if that would handle it better. Also in my Python code I’ve written retry logic. I’m not sure if that would make sense to put in the Ruby libraries.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants