Mod ndb scripting

mod_ndb

Contents

[edit] Scripting mod_ndb with PHP, Perl, or any Apache scripting language

[edit] Introduction

When mod_ndb is used directly from an HTTP client, each request corresponds to a single NDB operation, performed inside of a transaction. One great design strength of NDB Cluster, however, is the ability to obtain very high database performance by batching many operations into a single transaction.

The way to take advantage of "batched" NDB operations in mod_ndb is through simple scripting. A client, rather than making a request to mod_ndb directly, sends its request to a script written in PHP, mod_perl, or some other language that is embedded in Apache. The scripting language makes several requests into mod_ndb, followed by a special request to commit the transaction. It then retrieves the results, and perhaps processes them further or forwards them directly to the client.

Scripting for mod_ndb is based on two features of Apache: subrequests and the notes table. A script uses subrequests to send each request to mod_ndb. It may also use Apache notes to refine some requests. To complete a batch, it uses a special subrequest to commit the transaction. Finally, it finds the results of the read operations in Apache's notes.

[edit] Apache Notes

ndb_requst_method 
A script can set the note ndb_request_method to POST or DELETE, in order to simulate an HTTP POST or DELETE in a subrequest. If this note is not set, mod_ndb will interpret the subrequest as an HTTP GET. Inside mod_ndb this note will be unset (cleared) each time it is used. To make successive POSTs or DELETEs, a script should reset the ndb_request_method note for each request.
ndb_request_data 
Whenever a script sets ndb_request_method to POST, it should use the ndb_request_data note to send the "POST data" to mod_ndb. The data should be URL-encoded, e.g. username=jdd&status=connected.
ndb_result_0 , ndb_result_1 , etc. 
After mod_ndb commits a transaction, it places the result of the first GET (i.e. read) query of the batch in a note called ndb_result_0, the results of the second in the note ndb_result_1, and so fort.

[edit] An Example in PHP

<?php

virtual("/ndb/ex/1/session/3");
virtual("/ndb/ex/1/session/1");
virtual("/ndb-commit-all");


echo "ndb_result_0: " . apache_note("ndb_result_0") . "</br>\n";
echo "ndb_result_1: " . apache_note("ndb_result_1") . "</br>\n";

$x = json_decode(apache_note("ndb_result_1",true));
var_dump($x);

?>

Retrieved from "http://forge.mysql.com/wiki/Mod_ndb_scripting"

This page has been accessed 2,514 times. This page was last modified 04:02, 27 February 2007.

Find

Browse
MySQLForge
Main Page
Current events
Recent changes
Random page
Help
Edit
Edit this page
Editing help
This page
Discuss this page
Post a comment
Printable version
Context
Page history
What links here
Related changes
My pages
Special pages
New pages
File list
Statistics
Bug reports
More...