News for hackers. Stuff that matters.
Re:Redis-V8 by kelvin0 on Tuesday June 11, 2013 @08:25AM (#5861223)
Why would I choose to use JS in a DB? Why, oh why? This language has more quirks then a 2012 US Republican Presidential candidate.
Re:Redis-V8 by kryten on Tuesday June 11, 2013 @08:40AM (#5861285)
That's the first thing I thought.

Having spent literally the last 10 years removing stored procedures and extensions from software products to eek out a little more from the black box that is a database engine and remove all the rats nest of logic, why would I want to go and do the same all over again?

Of all the things I've learned in the last 20 years or so, you shouldn't stick any logic or programmability inside the database engine. It's hell down the line.

And don't get me started on where the programmability abstraction gets fudged in with the data resulting in executable data and all sorts of security hell.

Re:Redis-V8 by kijin on Tuesday June 11, 2013 @09:06AM (#5861436)
In a key-value store like Redis, it's actually quite useful to be able to generate an atomic query that says something like "If List A contains B, return C. Otherwise check whether List D contains E, and if so, return all the keys and values of Dictionary F, but otherwise return zero."

But of course, Redis already has Lua scripting which is a nearly perfect fit for its use case. JavaScript looks terribly cluttered by comparison. Some sort of V8 integration might make sense if the goal is to make Redis even easier to use with node.js, but I don't see anything in the documentation to suggest that this is what's happening.

Re:Redis-V8 by kryten on Tuesday June 11, 2013 @09:38AM (#5861641)
Couldn't this be handled with some conditional primitives like in ARM assembly adequately?

Actually that's not a bad idea ... writes it down...

Re:Redis-V8 by andrewflnr on Tuesday June 11, 2013 @09:15AM (#5861482)
Exactly what bad things happen when you put logic in the database? At my current employer, most business logic is in stored procedures.
Re:Redis-V8 by kryten on Tuesday June 11, 2013 @09:32AM (#5861605)
Lots. Here you go:

1. CPU time goes up. When you need to scale up, your brick wall is a lot closer.

2. When you do need to scale up, moving it out of the database engine is very expensive and time consuming.

3. The languages are archaic, obtuse and inadequate for representing business logic and don't cover ALL concerns. How do you call a web service and do an update in a transaction for example? How do you send an email?

4. It's incredibly difficult to test as the entire thing is stateful.

5. Error handling and reporting is terrible.

6. You lose database portability. This is a big issue these days, particularly when you get whacked with major licensing model changes.

7. Versioning and deployment with the application is utterly painful.

Etc etc...

Re:Redis-V8 by andrewflnr on Tuesday June 11, 2013 @10:01PM (#5866016)
Haha, well, we're running a small site on a huge server and we're not that into automated testing. We actually send email by inserting into a table that serves as a queue. SQL server already costs a fortune. Honestly, though, I've felt a lot of that already, but didn't really attribute it to stored procedures.

Can you explain why stored procedures are faster than code in my app? It seems like they're both run in a fairly optimized VM, but I don't know much about the details. We're using C# at work, but if I was using something like Python I would be more tempted to move things into the db for performance reasons.

Re:Redis-V8 by kryten on Wednesday June 12, 2013 @04:35AM (#5867117)
It depends entirely on round trips to the server and your use cases.

Generally speaking though, if you keep your result set as narrow as possible, post process aggregates in code, keep your join count low and keep you round trips per request low then c# will destroy stored procedures.

Re:Redis-V8 by Shorel on Tuesday June 11, 2013 @10:02AM (#5861782)
I don't think most of these apply to JavaScript nowadays.
Re:Redis-V8 by andrewflnr on Tuesday June 11, 2013 @09:55PM (#5865990)
Personally, I'm interested in the general answer.
Re:Redis-V8 by ironchef on Tuesday June 11, 2013 @09:34AM (#5861619)
The usual culprits are scaling and versioning / config mgmt; however, anything can be misused (and there's no one size fits all). I've seen it done well once. Once.
Re:Redis-V8 by kryten on Tuesday June 11, 2013 @09:36AM (#5861627)
That's one more time than me :)
Re:Redis-V8 by twistedpair on Tuesday June 11, 2013 @09:45AM (#5861682)
So many times I've seen people picking up the pieces of a "We'll just do everything in SP's!" project architecture." Anti-pattern city. The typical answer to make it scale or maintain well is to just throw it out.
Re:Redis-V8 by dagw on Tuesday June 11, 2013 @09:52AM (#5861715)
Honest question. Where should you stick your db related logic if you don't want to replicate it in every app that touches the database. Do you write some sort of middleware that sits between the apps and the database and never let any apps talk directly to the database?
Re:Redis-V8 by kryten on Tuesday June 11, 2013 @09:59AM (#5861759)
Exactly that. The "middleware" as you put it can manifest itself as one of several things (vastly simplified explanations):

1. Sits in front of your data store and exposes your application's API via HTTP for example. Typical SOA/public API type architecture.

2. Sits inside your web application as a component which you talk to via your internal API. In a Ruby/Python/PHP/Java/C# setting, you would typically have a class with methods on it which correspond to API calls.

3. Ships with your application (if a desktop one for example) and serves an internal API. As above but the component ships with the desktop application.

We do 1 and 2 in our product using the same shared components (domain models).

In actual fact, it's completely hiding behind NHibernate so we don't actually ever consider the database as part of the problem that needs solving. It's purely where we put our stuff when we don't want it in memory.

Re:Redis-V8 by h0x91b on Tuesday June 11, 2013 @08:46AM (#5861318)
1) JS is easy, almost everyone can work with it. 2) V8 is faster than LUA 5-10 times........ 3) MVC - Model and crons, i think should be in DB.
Re:Redis-V8 by __alexs on Tuesday June 11, 2013 @09:19AM (#5861507)
You know there is a redis fork that uses LuaJIT right? https://github.com/neomantra/redis
Re:Redis-V8 by tete on Tuesday June 11, 2013 @09:21AM (#5861521)
2) Faster than LUA-JIT? Since when?
Re:Redis-V8 by wheaties on Tuesday June 11, 2013 @09:23AM (#5861536)
You know what's faster than JS? C. C, the language many VMs are built in and tasked with running these kinds of things.
Re:Redis-V8 by evilduck on Tuesday June 11, 2013 @09:50AM (#5861706)
And ASM is faster than C.

Javascript strikes a nice balance between performance and high level usability.

Re:Redis-V8 by Shorel on Tuesday June 11, 2013 @10:08AM (#5861821)
V8 faster than Lua-JIT sounds like a really bold claim. AFAIK it is the other way around, with a factor of 3x.
Re:Redis-V8 by h0x91b on Tuesday June 11, 2013 @12:24PM (#5862792)
Nope, in redis v8 is faster, just because i have optimised GET/SET/INCR commands, and lua use a regular connection to DB like any other client, so in my case is no need to parse/encode redis format. And i can optimise any other redis functions for v8.
Re:Redis-V8 by andrewflnr on Tuesday June 11, 2013 @10:04PM (#5866027)
And it's not possible to do the same for Luajit? Doesn't sound like a fair comparison.
Re:Redis-V8 by h0x91b on Wednesday June 12, 2013 @12:54AM (#5866587)
I started this project because javascript is more convenient and easier to teach (everyone knows). The fact that the V8 found in 10(!) Times faster than the native commands even through pipelining, it was found out only later. And as I said, none of my friends can not use LUA to do something serious, but easy to work with javascript. Most of what I've done is independent of the language I use a different approach to scripting the database.

Now cron can do directly in the database. The results you can obtain using REST request (with gzip is very less traffic). On the javascript there is a huge amount of libraries, such as Crypto, if desired, there will be templates to insert. When I finish the beta, it will be possible to write map / reduce function on the clusters. The differences will be very much.

Re:Redis-V8 by andrewflnr on Wednesday June 12, 2013 @06:52PM (#5871237)
You presume a great deal. "Everyone knows"? I've always found Lua to be a much nicer language than JS, certainly with far fewer ways to shoot yourself in the foot. I always thought "everyone knows" that. If it wasn't for the lack of libraries, Lua would be my first choice for teaching someone programming. "Doing something serious" in Lua is mainly hindered by the aforementioned lack of libraries/platforms, compounded by lack of experience.
Re:Redis-V8 by h0x91b on Saturday June 15, 2013 @06:47PM (#5886551)
Personally I do not like LUA, I do not force anyone to use JS. My opinion is that JavaScript is a powerful and handy, but again, this is only my opinion.
Re:Redis-V8 by Shorel on Thursday June 13, 2013 @10:12AM (#5874101)
Yes, but the easy of use of JavaScript is orthogonal to the performance claims.

Also, keep in mind that I wrote Lua-JIT, not Lua. There's a big performance difference between them too.

Re:Redis-V8 by h0x91b on Saturday June 15, 2013 @06:50PM (#5886569)
I will perform the test on the speed of Lua-jit, but I wrote redis-v8 not for speed. The fact that the V8 was faster than Lua (regular) was a surprise for me.
Re:Redis-V8 by diminish on Tuesday June 11, 2013 @09:03AM (#5861417)
i wonder if JS will empower any embedded hw projects soon. writing the next mars rover in js anyone?
Re:Redis-V8 by kryten on Tuesday June 11, 2013 @09:40AM (#5861655)
No, because it's entirely non deterministic and mostly an evolved shit-crock rather than an engineering tool.
Re:Redis-V8 by bayesianhorse on Tuesday June 11, 2013 @08:31AM (#5861251)
Because some databases have a significant usage among web developers and web developers have a significant expertise in javascript.
Re:Redis-V8 by Argorak on Tuesday June 11, 2013 @09:09AM (#5861449)
Which sadly doesn't mean that they have a lot of experience in the algorithms involved when handling datasets.
Re:Redis-V8 by weego on Tuesday June 11, 2013 @09:38AM (#5861646)
Since when does every use of a database involve handling datasets in a way that needs experience and "algorithms". A key value store can be used as... a key value store if need be. It doesn't need to be crazy science.
Re:Redis-V8 by Argorak on Tuesday June 11, 2013 @09:41AM (#5861660)
Once you start scripting your K/V store, its not a simple K/V store anymore.

I am not against databases with scripting capabilities and I do not think javascript/front end developers are per se naive, but I've far to often seen the naive assumption that just because its javascript, everyone can handle it.

Re:Redis-V8 by jmcdonald-ut on Tuesday June 11, 2013 @09:58AM (#5861750)
This isn't true. Once you have tens of thousands of records, a poorly written algorithm or data structure is going to lead to O(n^2) behavior. That hurts. Even small sites can hit this amount of database records with ease.
Re:Redis-V8 by bsg75 on Tuesday June 11, 2013 @10:25AM (#5861917)
So if database developers have significant experience in SQL, they should author websites using templating engines that generate HTML using SQL?

(This is only partially sarcastic as there were a few RDBMS + HTML template products that mercifully died).