SlideShare una empresa de Scribd logo
1 de 58
Descargar para leer sin conexión
RIA 的强力后盾: REST+ 海量存储
        54chen@QClub
    http://www.54chen.com
             2010.7
学佛越久 离佛越远
   1999 html
   2000 cgi
   2001 asp
   2002 xhtml
   2003 flash
   2004 ajax
   2005 php perl java
   2006~now RIA
   FE html ajax flash flex air silverlight...
   BE cgi perl asp php asp.net java c c++
   WEB server PWS IIS apache tomcat resin jboss oc4j 
     lighttpd nginx
" 学了这么久 你有多远了? "
" 你还记得大明湖畔的 POST GET DELETE PUT 吗? "
REST
Roy T. Fielding 在他的博士学位论文中定义了术语
REST

http://www.ics.uci.edu/~fielding/pubs/dissertation/top
.htm
http://www.redsaga.com/opendoc/REST_cn.pdf
"Roy 是谁? "
 "Roy 是 HTTP 和 URIs 的设计者,是许多基本 Web 协
议的主要设计者。 "
什么是 REST
什么是 REST
   网络上的所有事物都被抽象为资源
     ( resource );
   每个资源对应一个唯一的资源标识( resource 
     identifier );
   通过通用的连接器接口( generic connector 
     interface )对资源进行操作;
   对资源的各种操作不会改变资源标识;
   所有的操作都是无状态的( stateless )。
什么是 REST
   URI 标识资源
   幂等性保证了你可以简单地再发送一次请求解
     决问题
   POST 方法既不安全也不具有幂等性
   所有资源使用了同样的接口
你可能认为你的应用包含了超出这些操作表达范围的逻
辑。
请允许我花费一些时间来让你相信不存在这样的情况。
REST 例子
http://example.com/customers/1234
http://example.com/orders/2007/10/776654
http://example.com/products/4554
http://example.com/processes/salary­increase­234  
   GET /customers/1234 HTTP/1.1
   Host: example.com 
   Accept: text/x­vcard 
违背 REST 约束的原因可归咎于对其好处认知的缺乏
被遗忘的 PUT DELETE
" 这些和我有什么关系呢?你太狂热了 "
" 当然有关系,当 Server 只剩下 CURD 时。。。 "
" 这意味着什么? "
"PHP JAVA...Bye"
未来的项目我们只需要做:


    用 RIA 完成   所有的调用与显示与逻辑
   增加 后端 的 负载能力
☺ 中间部分呢?
☺ 中间部分是一个完全不关心业务逻辑的 REST 框
架
Function REST(uri, request) {
   if(request == get) data = getDataFrom(table);
   if(request == post) data = createDataFrom(table);
   if(request == put) data = updateDataFrom(table);
   if(request == delete) data = deleteDataFrom(table);
   Retrun dataParser(data); //json xml and so on
 }
使用中的牛 X 项目 :
   OpenResty­­ Yahoo AgentZh Perl 
     http://search.cpan.org/dist/OpenResty/
   Nginx openresty plan ­­ TaoBao C/C++ 
     http://www.pgsqldb.org/mwiki/index.php/Nginx_
     openresty_plan
   http://fun.yahoo.cn/admin/login.html
openResty
   最早, js+perl 框架
   提供: js 库( ajax 封装)和 perl 的 REST 服务
     端
现在: ngx_openresty




 ♡ We'd call this whole set of nginx modules
                ngx_openresty
and our work is heavily funded by Taobao.com.
Nginx conf REST




   nginx.conf 编程
location ~ '^/cat/(d+)' {
    set $id $1;
    set_form_input $name;
    set_quote_sql_str $quoted_name $name;

   postgres_query GET "select * from cats
where id=$id";
   postgres_query DELETE "delete from cats
where id=$id";
   postgres_query POST "insert into cats (id,
name) values($id, $quoted_name)";

     postgres_pass my_pg_backend;
 }
如何增加后端的负载能力?
CLOUD
"DB 压力太大,分库吧! "
" 听说 key value 的系统不错 "
    " 那还在等什么? Do it!"
☺ 需求:高并发、高可用性、高扩展性、海量存
           储.
前因后果
   Dynamo  Amazon 的高效 Key­Value 存储基础组
     件 , 用于其 S3 服务,是我们要的东西
   Cassandra Facebook 2008 年开源,由 dynamo 团
     队维护。 facebook 、 twitter 、 digg 使用
   Voldemort Linkedin  开源。
    nuclear renren.com
一起进入分布式的世界
研究的重点: Key-value
我们将 key 分布到从 0 到 2 的 64 次方的圆环上
分区数量 >> 机器数量
数据分区可保障迁移时负载均衡
CAP 原则
   Consistency( 一致性 ) ,数据一致性,简单的说,就是数据复制
      到了 N 台机器,如果有更新,要 N 机器的数据是一起更新
      的。
   Availability( 可用性 ) ,好的响应性能,此项意思主要就是速
      度。
   Partition tolerance( 分区容错性 ) ,这里是说好的分区方法,体现
      具体一点,简单地可理解为是节点的可扩展性。
   定理:任何分布式系统只可同时满足二点,没法三者兼顾。
   忠告:架构师不要将精力浪费在如何设计能满足三者的完美分
     布式系统,而是应该进行取舍。
数据在网络中往往不止一份
NRW 审视 CAP 原则
在 Dynamo 系统中,第一次提出来了 NRW 的方
法。
N - 复制的次数
R - 读数据的最小节点数
W – 写成功的最小分区数

这三个数用来灵活地调整 Dynamo 系统的可用性与
一致性。
R=1 :最少需要去一个节点读数据即可,读到即返
回,可用性是很高的,但并不能保证数据的一致性

同时 W=1 :可用性更新是最高的一种情况,但这
时完全不能保障数据的一致性,因为在可供复制的
N 个节点里,只需要写成功一次的话就返回了,也
就意味着,有可能在读的这一次并没有真正读到需
要的数据(一致性相当的不好)。
A 增大 C 减小
W=R=N=3: 写保证所有要复制的点都写成功,读的
时候也是都读到,这样子一定读出来的数据是正确
的,但是这中间的性能大打折扣,也就是说,数据
的一致性非常的高,但系统的可用性却非常低了。
C 增大 A 减小
数据分区让整个网络的可扩展性其实是一个固定值
(你分了多少区,实际上网络里扩展节点的上限就
是这个数),通过 NRW 来达到另外两个方向上的
调整。
这真的能实现吗?性能还有保障吗 ?
实现
   Dynamo  Amazon 的高效 Key­Value 存储基础组
     件 , 用于其 S3 服务,是我们要的东西
   Cassandra Facebook 2008 年开源,由 dynamo 团
     队维护。 facebook 、 twitter 、 digg 使用
   Voldemort Linkedin  开源。
    nuclear renren.com
性能
   提高引擎速度,提高 CLOUD 速度 ...
The future
更强大的海量存储方案
  更多 Rest 框架
 更炫的 RIA 应用
RIA 需要:




硬件加强,网速加快。
 信 X 哥,你懂的。
Thanks
   czhttp@gmail.com
http://www.54chen.com

Más contenido relacionado

Similar a Ria的强力后盾:rest+海量存储

Core rest edgarsilva_v1
Core rest edgarsilva_v1Core rest edgarsilva_v1
Core rest edgarsilva_v1Edgar Silva
 
DevInRio 2010 - NodeJS
DevInRio 2010 - NodeJSDevInRio 2010 - NodeJS
DevInRio 2010 - NodeJSEmerson Macedo
 
可复制的前后端分离开发模式
可复制的前后端分离开发模式可复制的前后端分离开发模式
可复制的前后端分离开发模式taobao.com
 
ADO.NET Entity Framework 4
ADO.NET Entity Framework 4ADO.NET Entity Framework 4
ADO.NET Entity Framework 4Raffaele Fanizzi
 
Seguridad en Servicios Web
Seguridad en Servicios WebSeguridad en Servicios Web
Seguridad en Servicios WebHacking Bolivia
 
Seminario Ruby On Rails Aula Open Source
Seminario Ruby On Rails Aula Open SourceSeminario Ruby On Rails Aula Open Source
Seminario Ruby On Rails Aula Open SourceSergio Alonso
 
Entity+framework+
Entity+framework+Entity+framework+
Entity+framework+Rey zhang
 
A Picture of Cassandra in the Real World - StampedeCon 2014
A Picture of Cassandra in the Real World - StampedeCon 2014A Picture of Cassandra in the Real World - StampedeCon 2014
A Picture of Cassandra in the Real World - StampedeCon 2014StampedeCon
 
以数据驱动为中心-FreeWheel
以数据驱动为中心-FreeWheel以数据驱动为中心-FreeWheel
以数据驱动为中心-FreeWheelairsex
 
Webperfdays 2014 - common web performance mistakes
Webperfdays 2014  - common web performance mistakesWebperfdays 2014  - common web performance mistakes
Webperfdays 2014 - common web performance mistakesdkoston
 
Uso de la Programación para la Seguridad en Redes (a.k.a. Sockets y Shellcoding)
Uso de la Programación para la Seguridad en Redes (a.k.a. Sockets y Shellcoding)Uso de la Programación para la Seguridad en Redes (a.k.a. Sockets y Shellcoding)
Uso de la Programación para la Seguridad en Redes (a.k.a. Sockets y Shellcoding)Pedro Valera
 
03 3-create-db-application-ado-dot-net Create Database Application with using...
03 3-create-db-application-ado-dot-net Create Database Application with using...03 3-create-db-application-ado-dot-net Create Database Application with using...
03 3-create-db-application-ado-dot-net Create Database Application with using...Warawut
 
HTML5 WebSocket 발표 자료
HTML5 WebSocket 발표 자료HTML5 WebSocket 발표 자료
HTML5 WebSocket 발표 자료Zany Lee
 
Nodejs on android
Nodejs on androidNodejs on android
Nodejs on android俊夫 森
 
Aspetos gerais de desenvolvimento web.
Aspetos gerais de desenvolvimento web.Aspetos gerais de desenvolvimento web.
Aspetos gerais de desenvolvimento web.Corcioli
 

Similar a Ria的强力后盾:rest+海量存储 (20)

Core rest edgarsilva_v1
Core rest edgarsilva_v1Core rest edgarsilva_v1
Core rest edgarsilva_v1
 
DevInRio 2010 - NodeJS
DevInRio 2010 - NodeJSDevInRio 2010 - NodeJS
DevInRio 2010 - NodeJS
 
可复制的前后端分离开发模式
可复制的前后端分离开发模式可复制的前后端分离开发模式
可复制的前后端分离开发模式
 
FISL11 2010 - Automação de Datacenters
FISL11 2010 - Automação de DatacentersFISL11 2010 - Automação de Datacenters
FISL11 2010 - Automação de Datacenters
 
ADO.NET Entity Framework 4
ADO.NET Entity Framework 4ADO.NET Entity Framework 4
ADO.NET Entity Framework 4
 
Seguridad en Servicios Web
Seguridad en Servicios WebSeguridad en Servicios Web
Seguridad en Servicios Web
 
Seminario Ruby On Rails Aula Open Source
Seminario Ruby On Rails Aula Open SourceSeminario Ruby On Rails Aula Open Source
Seminario Ruby On Rails Aula Open Source
 
Entity+framework+
Entity+framework+Entity+framework+
Entity+framework+
 
A Picture of Cassandra in the Real World - StampedeCon 2014
A Picture of Cassandra in the Real World - StampedeCon 2014A Picture of Cassandra in the Real World - StampedeCon 2014
A Picture of Cassandra in the Real World - StampedeCon 2014
 
Jetty Introduction
Jetty IntroductionJetty Introduction
Jetty Introduction
 
以数据驱动为中心-FreeWheel
以数据驱动为中心-FreeWheel以数据驱动为中心-FreeWheel
以数据驱动为中心-FreeWheel
 
MS Swit 2010
MS Swit 2010MS Swit 2010
MS Swit 2010
 
Webperfdays 2014 - common web performance mistakes
Webperfdays 2014  - common web performance mistakesWebperfdays 2014  - common web performance mistakes
Webperfdays 2014 - common web performance mistakes
 
Teletex - Estrutura Convergente
Teletex - Estrutura ConvergenteTeletex - Estrutura Convergente
Teletex - Estrutura Convergente
 
Türsteher für Bohnen
Türsteher für BohnenTürsteher für Bohnen
Türsteher für Bohnen
 
Uso de la Programación para la Seguridad en Redes (a.k.a. Sockets y Shellcoding)
Uso de la Programación para la Seguridad en Redes (a.k.a. Sockets y Shellcoding)Uso de la Programación para la Seguridad en Redes (a.k.a. Sockets y Shellcoding)
Uso de la Programación para la Seguridad en Redes (a.k.a. Sockets y Shellcoding)
 
03 3-create-db-application-ado-dot-net Create Database Application with using...
03 3-create-db-application-ado-dot-net Create Database Application with using...03 3-create-db-application-ado-dot-net Create Database Application with using...
03 3-create-db-application-ado-dot-net Create Database Application with using...
 
HTML5 WebSocket 발표 자료
HTML5 WebSocket 발표 자료HTML5 WebSocket 발표 자료
HTML5 WebSocket 발표 자료
 
Nodejs on android
Nodejs on androidNodejs on android
Nodejs on android
 
Aspetos gerais de desenvolvimento web.
Aspetos gerais de desenvolvimento web.Aspetos gerais de desenvolvimento web.
Aspetos gerais de desenvolvimento web.
 

Ria的强力后盾:rest+海量存储