RSS

I coulda had a Google V8

October 3rd, 2008 Posted in Software Development


So I’ve been playing with Google’s new V8 JavaScript engine that was released along with Google’s Chrome browser. V8’s big claim to fame is that it compiles JavaScript code to machine language instead of interpreting it. This gives a nice speed improvement over other JavaScript engines.

I was interested in V8 for use in a scripted server application that I’ve been kicking around for a while. The idea is basically to create a core C++ app that exposes database and communication functionality to JavaScript. You then implement your business logic in JavaScript and rarely have to touch C++ code. You can add C++ code in the form of shared libraries that the server dynamically links so if you do need C++ code you don’t have to touch the core server.

It seemed like V8 would be a great choice for this application until I started getting into it. The problem is that V8 was created with Chrome in mind. Chrome uses separate processes for each browser tab so each tab has it’s own instance of the V8 engine. The V8 engine was designed so that there can only be one instance of the engine per process. In other words, the V8 engine is a singleton. The engine can only be executing a single script at any given time. If you want to create an application with multiple worker threads then you have to use a V8 Locker object to serialize your script execution. If you don’t then the scripts running in different threads will step on each other since they are accessing static member variables within V8. This makes using V8 in my server less desirable because it isn’t going to scale very well.

V8 does have the ability to create multiple contexts that will allow you to have isolated script environments but still only one script can execute at a time. There also appears to be a way to time slice script execution on multiple contexts. I haven’t played with this feature yet but I still don’t think it would address the scalability issue.

V8 would be ideal for a server application that uses worker processes instead of worker threads. I’m not sure I want to go down that path considering the complexity required.

I’m not knocking V8 in any way. It’s an awesome piece of work and the price is great!

I’ll post my V8 test code in a future article.

[del.icio.us] [Digg] [Reddit] [Technorati]

RSS feed | Trackback URI

Comments »

No comments yet.

Name (required)
E-mail (required - never shown publicly)
URI
Subscribe to comments via email
Your Comment (smaller size | larger size)
You may use <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> in your comment.