RavenDB - slow write/save performance?

Go To StackoverFlow.com

7

I started porting a simple ASP.NET MVC web app from SQL to RavenDB. I noticed that the pages were faster on SQL than on RavenDB.

Drilling down with Miniprofiler it seems the culprit is the time it takes to do: session.SaveChanges (150-220ms). The code for saving in RavenDB looks like:

var btime = new TimeData() { Time1 = DateTime.Now, TheDay = new DateTime(2012, 4, 3), UserId = 76 };
session.Store(btime);
session.SaveChanges();

Authentication Mode: When RavenDB is running as a service, I assume it using "Windows Authentication". When deployed as an IIS application I just used the defaults - which was "Windows Authentication".

Background: The database machine is separate from my development machine which acts as the web server. The databases are running on the same database machine. The test data is quite small - say 100 rows. The queries are simple returning an object with 12 properties 48 bytes in size. Using fiddler to run a WCAT test against RavenDB generated higher utilization on the database machine (vs SQL) and far fewer pages. I tried running Raven as a service and as an IIS application, but didn't see a noticible difference.


Edit

I wanted to ensure it wasn't a problem with a) one of my machines or b) the solution I created. So, decided to try testing it on Appharbor using another solution created by Michael Friis: RavenDN sample app and simply add Miniprofiler to that solution. Michael is one of the awesome guys at Apharbor and you can download the code here if you want to look at it.

Results from Appharbor

You can try it here (for now):

  1. Read: (7-12ms with a few outliers at 100+ms).

  2. Write/Save: (197-312ms) * WOW that's a long time to save *. To test the save, just create a new "thingy" and save it. You might want to do it at least twice since the first one usually takes longer as the application warms up.

Unless we're both doing something wrong, RavenDB is very slow to save - around 10-20x slower to save than read. Given that it re-indexes asynchronously, this seems very slow.

Are there ways to speed it up or is this to be expected?

2012-04-04 06:45
by Mike Gleason
try to stop the SQL Server instance running on that machine and monitor the performance of RavenDB again.If it takes very less time in that case, you can think of the issue where it is - UVM 2012-04-04 06:53
What sort of operations are you doing? What does the code looks like - Ayende Rahien 2012-04-04 11:26
What is the authentication mode that RavenDB is running with - Ayende Rahien 2012-04-04 11:26
@UNNI - I wasn't sure if you where kidding, but I did try stopping the SQL Server instance. It made no difference - Mike Gleason 2012-04-04 18:49
@Ayenda - See my edit. It turns out that the Save is taking much longer than the Query - Mike Gleason 2012-04-04 20:22
@Mike I was not sure about your environment when you posted your query before editing it.So just wanted to confirm that - UVM 2012-04-05 04:09


3

First - Ayende is "the man" behind RavenDB (he wrote it). I have no idea why he's not addressing the question, although even in the Google groups, he seems to chime in once to ask some pointed questions, but rarely comes back to provide a complete answer. Maybe he's working hard to to get RavenHQ off the ground?!?

Second - We experienced a similar problem. Below's a link to a discussion on Google Groups that may be the cause:

RavenDB Authentication and 401 Response.

A reasonable question might be: "If these recommendations fix the problem, why doesn't RavenDB work that way out of the box?" or at least provide documentation about how to get decent write performance.

We played for a while with the suggestions that were made in the thread above and the response-time did improve. In the end though, we switched back to MySQL because it's well-tested, we ran into this problem early (luckily) which caused concern that we might hit more problems and, finally, because we did not have the time to:

  1. fully test whether it fixed the performance problems we saw on the RavenDB Server
  2. investigate and test the implications of using UnsafeAuthenticatedConnectionSharing & pre-authentication.
2012-04-23 20:21
by Joe
Thanks Joe. It's pretty frustrating. RavenDB promotes it's self as "High performance - RavenDB is a very fast persistence layer for every type of data model."

Maybe it should say "High READ performance - although persistence is rather slow."

Fundamentally, I'm really surprised at how little response this question received. I would have thought that there was more community interest in RavenDB - Mike Gleason 2012-04-24 21:47



0

To summarize Ayende's response you're actually testing the summation of network latency and authentication chatter. As Joe pointed out there's ways you can optimize the authentication to be less chatty. This does however arguably reduce security, clearly Microsoft built security to be secure first and performance secondary. You as the user of RavenDB can choose if the default security model is too robust as it arguably is for protected server-to-server communication.

RavenDB is clearly defined to be READ orientated. 10-20x slower for writes than reads is entirely acceptable because writes are full ACID and transactional.

If write speed is your limiting factor with RavenDB you've likely not modeled transaction boundaries properly. That you are saving documents that are too similar to RDBMS table rows and not actually well modeled documents.

Edit: Reading your question again and looking into the background section, you explicitly define your test conditions to be an optimal scenario for SQL Server while being one of the least efficient methods for RavenDB. For data that size, that's almost certainly 1 document if it would be real world usage.

2012-05-21 20:51
by Chris Marisic
Unfortunately, I disagreed with much of the summary. I think something is wrong with RavenDB as it stands today. I don't know if its a design problem or a bug, but it goes beyond just "that's what we expect". Taking a 1/4 second to write/persist even the smallest object is crazy - Mike Gleason 2012-05-22 02:41
Actually, it's a summation of network latency and authentication chatter AND the query - isn't that how you deploy a web app on RavenHQ at AppHarbor? Also, don't SQL Server and MySQL deal with the same network latency and authentication chatter - but complete the write 10-20x faster - Mike Gleason 2012-05-22 02:41
ockquote>

less chatty...OK, then here's the question - Would you actually recommend deploying a web app configured to use the less chatty authentication? I haven't seen anyone come up with a scenario where they' actually recommend it and Microsoft clearly recommends against it by naming it "unsafeauthenticatedconnectionsharing".

Mike Gleason 2012-05-22 02:43
Try configuring the non-recommended connection option (UnsafeRequestSharing = true) and check if this improves performance at all. But it would be strange because read performance is good and it uses the same authentication as write - nightwatch 2012-05-22 08:31
@MikeGleason my next application is being deployed configured as such: https://groups.google.com/forum/#!searchin/ravendb/PreAuthenticate/ravendb/3WEfKaqUxL4/rVjYaki3LQsJ RavenDB is configured to only allow the web app to communicate to it, I use no kind of windows impersonation with security so from the information the MSDN provides I find there to be no additional risk for my usage. I do completely disagree with your assertion something is wrong. Could writes be more optimized? Probably. I'd much rather them spend dev time on things that matter more. Writes to reads are easily 50:1 to 1000: - Chris Marisic 2012-05-22 12:17
@nightwatch - I did try setting both UnsafeRequestSharing and PreAuthenticate = true per http://groups.google.com/group/ravendb/browsethread/thread/71c5981fa3117cc6/6519fa6911408509?showdocid=6519fa6911408509 and it does improve the response time significantly. The difference between read and write is the number and type of requests sent between the web server and DB Server. Fire up Fiddler and you'll see what I mean - just be careful about making too many assumptions with Fiddler running because it seems having a proxy in the middle can affect the number of requests in some instances - Mike Gleason 2012-05-22 15:54
Ads