Skip to content

Always return JS engine to pool after component render. #270

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

Merged
merged 2 commits into from
May 22, 2016

Conversation

dustinsoftware
Copy link
Member

This allows other threads to use available engines while other MVC actions are being processed during a page render.

This allows other threads to use available engines while other MVC actions are being processed during a page render.
@huan086
Copy link

huan086 commented May 19, 2016

On some of my pages, I render 2 or 3 separate components (i.e. 2 or 3 Html.React calls). Some of these calls are in Html.Partial. Will this change cause any issues?

@dustinsoftware
Copy link
Member Author

Nope, you should be just fine.

@Daniel15
Copy link
Member

Thanks! The only issue I can think of is if someone is relying on global state - For instance, if one component's render function sets a global variable, and then another component expects that variable to be set. I'd like to think that that's a rare use-case though. And in cases like that, the user can just disable engine pooling.

Could you please add a unit test, at least for the ReturnEngineToPool method (and ideally the HTML helpers, if it's not too difficult to write tests for them)?

@Daniel15 Daniel15 merged commit 4887288 into reactjs:master May 22, 2016
@dustinsoftware
Copy link
Member Author

FWIW we've been running this fix in production for a week now and have had no problems so far! 🎉

@mwethington
Copy link

dustin - how is it going after a month or so?

@dustinsoftware
Copy link
Member Author

Really well so far. One time one of the pooled v8 engines got in a weird
state and stopped responding - we had to recycle the app to fix it. That
has only happened one time. There is already an issue open somewhere about
that bug..

On Sun, Jul 17, 2016 at 11:15 Bill Bell [email protected] wrote:

dustin - how is it going after a month or so?


You are receiving this because you authored the thread.

Reply to this email directly, view it on GitHub
#270 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AA5hFjf34tMKuCNkDSsG1edwOSZOMiIfks5qWnEygaJpZM4Ih63p
.

@mwethington
Copy link

The fix appears to be in NuGet - v2.4 - right? Can we get a blog entry for 2.5? http://reactjs.net/blog/

https://www.nuget.org/packages/React.Web.Mvc4/

@mwethington
Copy link

OK 2.4 is the latest - 2.5 was for Core stuff changing.

@stuartharper01
Copy link

Hello.
Is this fix incorporated into the following NuGet versions please?:
React.Web 2.5.0
React.Web.Mvc4 2.5.0

I ask because I still get the following exception when Load Testing:
JSPool.Exceptions.JsPoolExhaustedException
Could not acquire JavaScript engine within 00:00:05

When I set the React config that stops JS pooling, the Exhausted exception goes away but the performance is adversely affected:
ReactSiteConfiguration.Configuration.SetReuseJavaScriptEngines(false);

Thanks

@Taritsyn
Copy link
Contributor

Taritsyn commented Feb 5, 2019

@Daniel15 @dustinsoftware More than a year ago, Daniil Sokolyuk developed his own implementation of the JSPool specifically for high-load sites.

@stuartharper01
Copy link

OK thanks. I can see the #270 fix in the source of React.Core\ReactEnvironment.cs.
But unfortunately, I still get the following exception during Load Tests:
JSPool.Exceptions.JsPoolExhaustedException
Could not acquire JavaScript engine within 00:00:05

@huan086
Copy link

huan086 commented Feb 5, 2019

You'll need to change your configuration to increase your max engines. You're most likely running out of engines in the pool when load gets high and it takes several seconds to execute the script

@huan086
Copy link

huan086 commented Feb 5, 2019

@DaniilSokolyuk could you provide some context to the optimization? What was the bottleneck in @Daniel15 's JSPool implementation?

I'm thinking of implementing my custom high-load JSPool using AsyncEx AsyncCollection. Daniel15's implementation uses BlockingCollection, which blocks threads from the ThreadPool. As load goes up, number of threads that get blocked goes up, available threads to serve non-React views goes down and the whole system slows to a crawl.

@DaniilSokolyuk
Copy link
Contributor

@huan086 Hi! I now reimplement JsPool i make it truly async without thread starvation
look
https://github.com/DaniilSokolyuk/ZeroReact.NET/blob/master/src/ZeroReact/JsPool/ZeroJsPool.cs

@dustinsoftware
Copy link
Member Author

@DaniilSokolyuk I’d be open to making it so the implementation of engine pooling is swappable, so consumers can choose either jspool or your implementation (or maybe your changes can go upstream into JSPool itself..)

@Daniel15
Copy link
Member

Daniel15 commented Feb 6, 2019

I'd be happy to accept pull requests to JsPool if you're willing to submit them 😃

@DaniilSokolyuk
Copy link
Contributor

ReactJS.Net has sync API,make JsPool async without change ReactJS.Net not make a sense, and in legacy asp you can’t use await in views, it will work only in asp net core
Ofc we can have async and sync api with .GetAwaiter().GetResult()

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

Successfully merging this pull request may close these issues.

8 participants