Search:

Search all manuals
Search this manual
Manual
Getting Started with Membase and Java
Additional Resources
Community Wiki
Community Forums
Couchbase SDKs
Parent Section
Getting Started with Membase and Java
Chapter Sections
Chapters

6. How to Build and Run the Sample Application

In order to build and run the sample application, you should unzip the attached sample to a directory on your hard drive. The sample application comes with an Eclipse project file and can easily be imported into Eclipse using the following:

  1. Choose File | Import > General > Existing Projects into Workspace.

  2. In the Import Project dialog, click the Browse button next to the Select root directory text field and navigate to where you unzipped the sample application.

  3. Make sure that the GettingStarted project is selected, and hit the Finish button.

You should now have the project imported into your project explorer in Eclipse. Next you will want to run the application.

  1. Right click the GettingStarted project and select Run As | Run Configurations

  2. Double click the "Java Application" node to create a new configuration.

  3. Name this "Membase Client".

  4. Click the "Main" tab.

  5. Click the Search button and choose the com.acme.membase.gettingstarted.Main class to run.

  6. Click the "Arguments" tab.

  7. In the "Program Arguments" tab type something like: "10.0.0.33:11211" 5

  8. Click the "Apply" button.

  9. Click the "Run" button.

Running this program generates the following output the first time:

Client-2 took 37.2500 ms per key. Created 35. Retrieved 65 from cache.
Client-3 took 37.7800 ms per key. Created 35. Retrieved 65 from cache.
Client-4 took 37.7100 ms per key. Created 35. Retrieved 65 from cache.
Client-0 took 37.8300 ms per key. Created 35. Retrieved 65 from cache.
Client-1 took 37.8400 ms per key. Created 35. Retrieved 65 from cache.

Running the program a second time before 15 seconds elapses, produces this output instead:

Client-1 took 4.6700 ms per key. Created 0. Retrieved 100 from cache.
Client-3 took 4.6000 ms per key. Created 0. Retrieved 100 from cache.
Client-4 took 4.7500 ms per key. Created 0. Retrieved 100 from cache.
Client-2 took 4.7900 ms per key. Created 0. Retrieved 100 from cache.
Client-0 took 4.8400 ms per key. Created 0. Retrieved 100 from cache.

There are a few things that are interesting about the output. In the first scenario, the five threads collaborate to produce the sequence of random numbers such that the average time per key is significantly less than 100ms. Each thread is creating 35 numbers, but reading 65 from the cache.

In the second run, because the 15 second timeout has not elapsed yet, all of the random numbers were retrieved from the cache by all of the threads. Notice that reading these values from Membase only takes a few milliseconds.