Introducing the Couchbase ASP.NET SessionState Provider

Source: Couchbase

One question I'll often ask developers on a phone screen for an ASP.NET developer position is to discuss the different options for managing session state in an ASP.NET application.  I like this question because it gives me quick insight into what types of applications that developer has been working on and what role that developer has played on his or her team.

The memorization part of the question is clearly to know the different out-of-the-box providers.  Developers who work on smaller sites or who don't have a production support role often know about in-process session state, but are unfamiliar with the out-of-process providers and the problems they solve. 

Over the years, I've found that a state server was often sufficient for a reasonably high traffic site.  But that has a single, and obvious, point of failure.  Managing session state with SQL Server is durable, but clearly it's going to be slower.  I've never been comfortable with increasing disk I/O on the database server for session management. 

The right answer seems to be to use a backing store that isn't I/O bound and doesn't depend on the uptime of a single server.  That description is one that applies to Couchbase Server.  So if you want the speed of using an in-memory session state server with the durability of a SQL Server instance, you now have the option of using the Couchbase ASP.NET session state provider.

Freshly posted to the CouchbaseLabs projects on GitHub, is a port of the former Enyim Memcached session state provider.  There's also a sample application included to get you up and running quickly. 

Using the new provider is very simple.  Assuming you have your cluster configured, all you need to do is update your web.config with the settings for the Couchbase .NET Client Library and update the sessionState config section.

<section name="couchbase"type="Couchbase.Configuration.CouchbaseClientSection, Couchbase"/>  
<couchbase>
    <servers bucket="default" bucketPassword="">
    <add uri="http://127.0.0.1:8091/pools/default"/>    
    </servers>
</couchbase>
<sessionState customProvider="Couchbase" mode="Custom">
  <providers>
    <add name="Couchbase"type="Couchbase.AspNet.SessionState.CouchbaseSessionStateProvider, Couchbase.AspNet" />
  </providers>
</sessionState>

Once these settings are in place, simply use the Session object (or ViewData, ViewBag and TempData in MVC) as you always have. 

Session["Message"] = "Couchbase is awesome!";

Don't forget that you'll need to mark your own classes as Serializable in order to persist them into Couchbase Server.

[Serializable]
public class SessionUser
{
    public string Username { get; set; }

    public string Email { get; set; }
}

Please note that this provider is included as part of Couchbase Labs and is not an officially supported product.  You're free to use the code however you'd like as it's licensed under Apache License 2.0. 

Improving CouchDB Performance

Source: SafariBooksOnline

In a previous piece titled The Technology Behind Couchbase I described the technology that underpins the functionality of the Couchbase Server 1.8 and the forthcoming Couchbase Server 2.0. In this post, I will show you how to improve the performance of CouchDB.

Within CouchDB, there is a one-to-one relationship between the design documents that you create, and the indexes that are produced in the process.

That’s important because if you put all 20 view definitions into one design document, all 20 views will be updated at the same time the next time someone accesses the view. The index is created when the view is accessed, and if there are lots of views to update then the time between sending the request and getting the reply can be significant.

One simple way to improve your performance is to reduce the number of view definitions in a single design document.

Using stale views

Another way is to make use of the stale parameter to your view. For example:

GET http://couchbase:5984/recipes/_design/recipes/_view/by_recipe?stale=ok

This tells CouchDB to return the view information based on the current index without forcing an update before the results are returned.

Obviously this is much quicker, because there’s no update occurring before the info is returned. But it runs the risk of returning old information, hence the stale moniker. Using this method for all your requests will mean your index is never updated.

Updating after

One solution to this is to continue to use stale views, but instead of specifying ok use the term update_after. This returns the index result as quickly as possibly by still using the stale view, but then asks CouchDB to update the index after the results have been returned:

GET http://couchbase:5984/recipes/_design/recipes/_view/by_recipe?stale=update_after

This updates the index after the results are returned, but may also delay queries made by other clients until the view update has been completed.

Using the _changes feed

CouchDB includes a _changes feed that outputs information when the database changes. You set a process to watch the changes feed and then trigger a view update when a specific number of changes have taken place. For example, the Python script below (which uses the couchdb module from http://code.google.com/p/couchdb-python/) monitors the changes feed for the recipes database, and requests the view (causing an update) when 10 changes have been received:

from couchdb import
Server                                                                                                                

cdbs = Server('http://localhost:5984/')
db = cdbs['recipes']
# the since parameter defaults to 'last_seq' when using continuous feed
ch = db.changes(feed='continuous',heartbeat='1000')                                                                                       

counter = 0                                                                                                                               

for line in ch:
    counter=counter+1
    if (counter > 10):
       db.view('recipes/by_name')
       counter = 0

You can now set all of your clients to use stale views, because this background process will update the view as changes are made to the DB, and you are no longer relying on your client requests to control your index updates.

About the Author

  A professional writer for over 15 years, Martin ‘MC’ Brown is the author and contributor to over 26 books covering an array of topics, including the recently published Getting Started with CouchDB. His expertise spans myriad development languages and platforms Perl, Python, Java, JavaScript, Basic, Pascal, Modula-2, C, C++, Rebol, Gawk, Shellscript, Windows, Solaris, Linux, BeOS, Microsoft WP, Mac OS and more. He is a former LAMP Technologies Editor for LinuxWorld magazine and is a regular contributor to ServerWatch.com, LinuxPlanet, ComputerWorld and IBM developerWorks. As a Subject Matter Expert for Microsoft he provided technical input to their Windows Server and certification teams. He draws on a rich and varied background as founder member of a leading UK ISP, systems manager and IT consultant for an advertising agency and Internet solutions group, technical specialist for an intercontinental ISP network, and database designer and programmer and as a self-confessed compulsive consumer of computing hardware and software. MC is currently the VP of Technical Publications and Education for Couchbase and is responsible for all published documentation, training program and content, and the Couchbase Techzone.

BigCouch 0.4 moved in

Source: H-Online

BigCouch, the highly available, fault-tolerant, clustered version of Apache's CouchDB NoSQL JSON document database, has been updated to version 0.4. BigCouch appears to users as if it were a single instance of CouchDB, when, behind the scenes, it is actually an elastic cluster of nodes working to store, index and retrieve views of the data. BigCouch is developed and maintained by Cloudant and released under an Apache 2.0 licence. Cloudant have also restated their intent to donate and integrate the core functionality of BigCouch into the Apache CouchDB project.

Version 0.4 brings BigCouch up to date, in API terms, with CouchDB 1.1.1 and now features "zones", which offer more control over where documents are persisted in the cluster. For example, Cloudant uses the feature to ensure that a copy of a customer's data exists in both of their geographically separate data centres. The developers have also added the functionality of CouchDB's replicator DB for better control of data replication. Other changes in 0.4 include the addition of native SSL support and FreeBSD support. A full list of the changes is available in the change log. BigCouch 0.4 is available to download from the project's github repository.

 

Business Model change by CouchDB founder

Source: XWiki

In an article on Business Insider I found out that Damien Katz, the founder of CouchDB, decided to move away from the Apache project and to the Couchbase project, leaded from the VC backed company Couchbase.

What he is doing is what I described in my previous blog articles:

First Damien Katz should be recognized and respected for his incredible Open Source contribution with the work he did with CouchDB.

Now one can understand that he might want to control more the future of his product and/or that he wants/needs to earn money out of his innovation and the success of it and/or that he wants to build up this innovation as fast as possible.

But in his article there are a few things that are not acceptable from my point of view:

  1. Not respecting his own project CouchDB and your own contributors by using the title that he used. The title basically say that whatever he does will be better and dismisses what the Open Source Community could make out of the code he contributed to. He might be right in the end if his model works out better, but it's a plain lack of respect
  2. He is not mentioning the Couchbase is built out of the Couchbase startup and that it's company funded by investors. He is indeed not mentionning that currently the couchbase code is Open Source (although it is now at the end of his post after Chris Anderson has mentionned it). Obvisouly many people understood that the move was about money. He might put some doubts in the head of people by stating that "everything" couchbase is open source at this moment. Now can he tell us that he can guarantee that in the FUTURE, "everything" couchbase does will be open source ? I'm pretty sure he won't, mostly because I'm pretty sure his investors would not agree with that and that it won't be the case in the future.

He should be honest about the real reasons of the move. It's because he is in a business oriented company, and wants to control the direction of the technology that is build, and he plans with his investors to make significant profits out of this work and that in the future his creations might not be open sourced.

It is very sad, that it seems that many Open Source companies are using the business model of gathering a community with the open source code, and then progressively close whatever they do in order to make more money out of it. I specifically mention "more money" out of it, because I personally believe that in most cases you can make money out of a respectfull open source strategy, but there are a few constrains there and probably one of them is to not need outside investors. This is what we try to do at XWiki SAS where we have a manifesto which explains the way we plan to behave and where we have commited ourselves to stick to our model.

Ludovic Dubost
Creator of XWiki Open Source Software and Open Source company XWiki SAS

Cloudant Plans to Wind Down BigCouch Development, Merge Features into Apache CouchDB

Source: SiliconAngle by Klint Finley

The drama regarding the future of Apache CouchDB is winding down and looks to have a happy ending. Following Couchbase’s announcement that it is discontinuing its own distribution of CouchDB, Cloudant announced that it is now in the process of merging its fork of CouchDB, called BigCouch, into the main CouchDB project. In an interview today, Cloudant CTO Adam Kocoloski confirmed to me that Cloudant will then wind down development of BigCouch after the merge and there will be just one major version of the NoSQL document database. Cloudant will then concentrate on developing CouchDB.

To recap the recent history: in February of 2011, CouchOne, a company co-founded by CouchDB creator Damien Katz as Couchio in 2009, merged with Membase to form Couchbase. The newly formed company announced its own distribution of CouchDB calledCouchbase Server Single. The company also began integrating features from CouchDB, such as peer-to-peer replication, into Membase to create the main Couchbase Server offering.

Cloudant, founded in 2008, has been developing BigCouch, which improves CouchDB’s clustering and scale-out abilities by adapting technologies from Amazon Dynamo, Amazon.com’s distributed database system. “At the time, we built BigCouch we decided to make it open source but keep it in its own repository because we were uncertain about how to make it work in the main Apache CouchDB project,” says Cloudant co-founder and President Alan Hoffman.

Last November, a poster on Hacker News noticed that according to Google Trends, CouchDB was declining in search popularity. Cloudant employee Tim Anglade speculated that it might have something to do with the fracturing of the CouchDB project between Couchbase Single Server, BigCouch and the original Apache project and the fact that neither Couchbase nor Cloudant were evangalising CouchDB.

Later that month, following the announcement that Canonical would replace CouchDB in Ubuntu One as its solution for syncing structured data, Couchbase SVP of Product James Phillips told me that the company no longer had any business interest in CouchDB. Shortly after, the company announced that it was ending its Couchbase Server Single offering. And yesterday, Katz announced that he will no longer contribute to CouchDB and will focus entirely on Couchbase Server.

Cloudant followed Katz’ announcement by announcing that it is contributing its BigCouch features into CouchDB. Since Couchbase Server is very much not CouchDB, there will be at last only one version of CouchDB. That means that moving forward Cloudant’s developement and evangalizing efforts can go fully towards the CouchDB.

Since CouchDB is an Apache project, there has never been an official corporate sponsor, but CouchOne was seen as the “go to” company for CouchDB. Since the merger with Membase (which many refer to as an acquistion of CouchOne by Membase), there’s been a leadership vacuum. And the end of support for CouchDB on the part of Couchbase has also led to uncertainty on the part of enterprise customers.

Couchbase gets to focus on its primary product, CouchDB gets a new sugar daddy, enterprise customers have a new company for support and Cloudant has a bright future ahead. It seems like wins all around.

Developing with .NET and Couchbase Server Webinar

Friday, January 27, 2012, 10AM PT, San Francisco 

6pm - London | 1pm - New York | Sat, Jan 28th at 5am - Sydney | Sat, Jan 28th at 3am - Tokyo | Sat, Jan 28th at 2am - Beijing | 11:30pm - Mumbai

Presented by: John Zablocki

Duration: Approximately 60 minutes.

Cost: Free

Couchbase Server 2.0, currently in Developer Preview, is a distributed key/value store database offering rich querying by way of views created using map/reduce. Those versed with Memcached or CouchDB will find reuse in their skills as Couchbase Server incorporates the best features from these two platforms.

In this webcast John Zablocki, Developer Advocate at Couchbase, will introduce the .NET client library for Couchbase Server. Topics covered will include:

  • Configuring the client
  • Persisting and retrieving key/value data and querying views

 

If you plan to attend this webcast please click the Register button below and we'll send you a reminder email.

Price: Free

Register Now

 

About John Zablocki

John Zablocki is a Developer Advocate at Couchbase, located in the Boston area. Couchbase develops and supports Couchbase Server, which can be found behind the some of the Web's largest applications. He is the organizer of Beantown ALT.NET, a monthly Meetup focusing on .NET and open source. John is also currently authoring a book on Orchard CMS for O'Reilly.

 

Jelastic Makes Java Hosting Easy and More Powerful with Apache CouchDB

Addition of fast growing, open source database CouchDB to Jelastic increases reliability and speed.

Palo Alto, CA, December 23, 2011 --(PR.com)-- Jelastic, the next-generation Java hosting platform, today announced the addition of Apache CouchDB, one of the fastest and most reliable distributed databases available – giving customers more choice and control over how they store their data. CouchDB makes replication and scaling across multiple data centers easy and reliable.

Apache CouchDB is a NoSQL, document-oriented database that is growing in popularity due its replication strengths, reliability and speed. CouchDB provides a RESTful JSON API that can be accessed from any environment that allows HTTP requests. Its “B-Tree” approach to data storage means that querying the database is really fast, regardless of the amount of data stored. CouchDB offers a masterless, simple and efficient replication, allowing an application to be run across multiple Jelastic hosting providers, providing redundancy against downtime. CouchDB’s reliability is increased by the fact that database file can’t be corrupted.

Jelastic makes it easy to upload Java applications. Jelastic eliminates the need to make changes to code or programming language. Jelastic users are not locked in to any one way of doing things and are free to choose what stacks they want. The Jelastic platform makes it easy to run and scale Java applications.

“We are really excited about making CouchDB available as a software stack in Jelastic,” said Ruslan Synytsky, CEO, Jelastic. “CouchDB is reliable and offers database replication that is unmatched. Pairing CouchDB with Jelastic gives developers greater freedom and choice, while providing a cutting edge solution to Java application hosting.”

Jelastic supports any JVM-based application, including Java 6, Java 7, JRuby, Scala and Groovy. Currently, Jelastic offers support for following SQL databases: MariaDB, MySQL and PostgreSQL. It also supports the MongoDB and CouchDB NoSQL databases. Jelastic supports a number of application servers, including Tomcat 6, Tomcat 7, GlassFish and Jetty. Jelastic provides load balancing and caching through the integration of NGINX, and developer tools integration via Maven and Ant plug-ins.

Jelastic has been in beta since mid-2011 and has more than 5,000 registered developers and continues to receive positive feedback. This online tutorial shows how fast and easy it is to build and deploy a Java application in Jelastic.
To sign up for a free beta of Jelastic, or to learn more, go to http://jelastic.com.

About Jelastic
Jelastic, Inc., a startup company based in Palo Alto, Calif., makes the Java server hosting platform for developers and hosting service providers. Jelastic is the only PaaS offering designed specifically for hosting service providers to deploy and make available to their customers. Jelastic automatically scales Java applications and allocates server resources required by applications, thus delivering the true next generation Java cloud computing. Learn more at http://jelastic.com.

Contact:

Judah Johns
281-940-4270
media@jelastic.com

Discontinuation of Couchbase Single Server

Source: Couchbase

..., Couchbase Single Server, our CouchDB distribution, will be discontinued effective in January. We have come to believe the Apache Software Foundation is a better place for the continued development of CouchDB and frankly it is clear to us that having our own packaging only served to confuse the market. We plan to contribute the packaging and documentation we built to the Apache CouchDB project where it can be put to good use by the community. Our developers, particularly those originally with CouchOne, will continue to be big contributors to CouchDB. But, as I said earlier, our singular company focus will be on Couchbase Server...

Using CouchDb as a filesystem with PHP

Source: DZone

One of the problems I need to solve in my clustered PHP applications is where to store files. When I say files I’m not speaking about source code. I’m speaking about additional data files, such as download-able pdfs, logs, etc. Those files must be on every node of the cluster. One possible approach to the solution is to use a distributed filesystem, rsync or maybe use a file-server mounted on every node. Another solution may be the usage of CouchDb. CouchDb has two great features to meet or requirements with this problem. It allows us to store files as attachments and it also allows to perform a great and very easy multi-master replica system.

The usage of CouchDB is pretty straightforward. It implements a RESTfull interface to perform every operations. So the only thing we need is a REST client. Zend Framework has a great one. We dont’t really need a library. We can easily perform REST requests with the PHP’s Curl’s extension. I’ve created two libraries for working with CouchDb one is a low-level HTTP client (with curl) and another is higher level one (it uses the HTTP Client) for CouchDB operations. You can read two post about those libraries here and here.

Now I want to extend the features of my library. I want to use CouchDB as file storage in PHP. Instead of using file functions (fopen, fwrite, fread, …) I want to use another ones and store/read files in CouchDB. For doing this I’ve refactored those two libraries into another one called Nov. I also have embraced namespaces so I will use them in the library. This means it’s only available with PHP 5.3.

Here you are a summary of the library. That’s not a complete UML graph. It’s only a diagram with the main features only with educational purpose.

summary

The best to show the library is with an example:

First I’m going to start with the basic usage of Nov\CouchDb library:

01 // Starting up the loader
02 require_once("Nov/Loader.php");
03 Nov\Loader::init();
04  
05 use Nov\CouchDb;
06 $cdb new CouchDb('localhost', 5984);
07 $cdb->db('users');
08 $nombre $cdb->db('ris_users')->select('gonzalo')->asObject()->name;
09 $apellido $cdb->db('ris_users')->select('gonzalo')->asObject()->surname;
10 echo "Hello {$nombre} {$apellido}.
11 ";

To allow me the use of different CouchDb Databases and to put the Database configuration in one file. I use the following configuration class:

01 class NovConf
02 {
03     const CDB1 = 'CDB1';
04     const PG1  = 'PG1';
05  
06     public static $_dbs array(
07         self::PG1  => array(
08             'driver'   => 'pgsql',
09             'dsn'      => 'pgsql:dbname=pg1;host=localhost',
10             'username' => null
11             'password' => null,
12         ),
13         self::CDB1  => array(
14             'driver'   => 'couchdb',
15             'host'     => 'localhost',
16             'port'     => 5984,
17             'protocol' => 'http',
18             'username' => null,
19             'password' => null,
20         ),
21     );
22 }

As you can see I use the same configuration file for my PDO drivers and CouchDb.

Now I can use:

01 require_once("Nov/Loader.php");
02 Nov\Loader::init();
03  
04 use Nov\CouchDb;
05 $cdb = CouchDb::factory(NovConf::CDB1)->db('users');
06  
07 try {
08     $cdb->insert('xxx'array('name' => 'xxx'));
09 } catch (CouchDb\Exception\DupValOnIndex $e) {
10     echo "Already created\n";
11 }
12  
13 $data $cdb->select('xxx')->asObject();
14 $cdb->update('xxx'array('name' => 'xxx1'));
15 $cdb->delete('xxx')->asObject();

And now finally the file storage part:

For storing the files I’ve taken one design decision. Every files will be stored into separate CouchDb document. That’s means one file, one document. There’s another possible approach. One CouchDb document can be one folder and store every files as attachments of this folder in the same document. But I prefer the idea of not to track folders. Only files. So each CouchDb document will have only one attachment.

That’s an example of one document in CouchDb

01 {
02    "_id""/home/gonzalo/aasa.txt",
03    "_rev""2-48b501a81c38fd84a3e0351917e64135",
04    "path""/home/gonzalo",
05    "_attachments": {
06        "aasa.txt": {
07            "stub"true,
08            "content_type""application/octet-stream",
09            "length": 12,
10            "revpos": 2
11        }
12    }
13 }

There’s another usage script. Here we can see all the features together. We create files, update and delete them. Internally Nov\CouchDb\Fs uses a predefined CouchDb database called fs.

01 use Nov\CouchDb\Fs;
02 use Nov\CouchDb\Fs\Exception;
03 require_once ("Nov/Loader.php");
04 Nov\Loader::init();
05  
06 echo "<pre>";
07 // create an instance from a factory method
08 $fs = Fs::factory(NovConf::CDB1);
09 // Now we're going to delete a file. If it doesn't exists will throw a FileNotFound exception
10 try {
11     $fs->delete("/home/gonzalo/aaa.txt");
12 } catch (Exception\FileNotFound  $e) {
13     echo $e->getMessage() . "\n";
14 }
15 // Now we are going to create a file.
16 // the second parameter 'true' means if the file doesn't exist will be created. Similar than 'r+'
17 try {
18     $fs->open("/home/gonzalo/aaa.txt", true)
19     ->write("asasasasasas""application/octet-stream");
20 } catch (Exception\FileNotFound $e) {
21     echo $e->getMessage() . "\n";
22 } catch (Exception\WriteError $e) {
23     echo $e->getMessage() . "\n";
24 } catch (Exception $e) {
25     echo $e->getMessage() . "\n";
26 }
27 // We open the file
28 $res $fs->open("/home/gonzalo/aaa.txt");
29  
30 // we can get the length and the content type
31 echo $res->getLenght() . "\n";
32 echo $res->getContentType(). "\n";
33 // We move it to another location
34 $to "/another/location";
35 $res->move($to);
36  
37 $res $fs->open($to);
38 // we flush the file to the browser
39 echo $res->raw();
40  
41 // finally we delete it
42 $res->delete();
43 echo "</pre>";

I’ve also created an extra class to allow to dump files from filesystem to CouchDb and vice-versa.

1 require_once ("Nov/Loader.php");
2 Nov\Loader::init();
3 echo "<pre>";
4 // from filesystem to couchdb
5 \Nov\CouchDb\Fs\Utils::fs2cdb("/path/from/", NovConf::CDB1);
6 // from couchdb to filesystem
7 \Nov\CouchDb\Fs\Utils::cdb2fs(NovConf::CDB1, "/path/to/");
8 echo "</pre>";

And that’s all. You can download the source code with the examples here. The examples are under document_root/tests/couchdb/ folder. Remember you will need PHP5.3.

About the author

 

Gonzalo Ayuso is a Web Architect with more than 10 year of experience in the web development, specialized in Open Source technologies. Experienced delivering scalable, secure and high performing web solutions to large scale enterprise clients.

 

Cloudant claims $2M funding

Cloudant Inc., a cloud data analytics software developer, has raised $2.1 million in an equity and stock funding indicated in a regulatory filingtoday. 

The Boston startup is focused on developing data tools to address web and mobile applications. Its CouchDB is a NoSQL document database that uses a querying and indexing engine. The company also offers an open-source version of CouchDB in BigCouch. NoSQL is a catch-all term for developers who reject the popular open-source database software MySQL.

Cloudant was not immediately available to discuss the $2.1 million funding, and the U.S. Securities and Exchange Commission filing did not disclose the backers of the financing. The company’s website noted Cambridge-based Avalon Ventures as a current investor.

Cloudant was founded in 2008 by three MIT physicists – CEO Alan Hoffman, CTO Adam Kocoloski and chief scientist Mike Miller. The company is backed by Avalon Ventures

In October, Cloudant entered into a joint agreement with agriculture giant Monsanto Co. to develop a next-generation platform that could speed up genome sequencing analysis in crops. The data integration and visualization platform is expected to be based on Cloudant’s BigCouch.