手机版
你好,游客 登录 注册 搜索
背景:
阅读新闻

Membase和Java入门

[日期:2011-08-16] 来源:Linux社区  作者:njchenyi [字体:大 中 小]

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.

Conclusion

You now know how to obtain the Membase Java client library, and write small Java programs to connect with your Membase cluster and interact with it. Congratulations, you will be able to save your servers from burning down, and impress your users with the blazing fast response that your application will be able to achieve.

linux
相关资讯       Java  Membase  
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款