实习log-day9-2019/07/19

背景

业务需求代码写的很快,需求也都可以完成,代码也同样可以解决。

但对项目使用的play框架,前端react框架,ebean数据框架依旧不明器所以然,故写此博客。

Play框架见闻

  • Play基于java和scala轻松构建web应用程序

在业务中也可以看到,play框架的使用使得开发变的简单许多;开发效率高,用Java开发效率直追RoR(Ruby on Rails)

  • Play 基于 Akka 构建,为高度可扩展的应用程序提供可预测的最小资源消耗(CPU,内存,线程)

AKKA框架是一个平台,灵感来自ERlang,能更轻松地开发可扩展,实现多线程安全应用。虽然在大多数流行的语言并发是基于多线程之间的共享内存,使用同步方法防止写争夺,Akka提供的并发模型基于Actors。

啥是actors?Actors提供一个简单统一模型:

  1. 隔离计算实体;
  2. "Share nothing";
  3. 没有任何地方同步;
  4. 异步消息传递;
  5. 不可变的消息;
  6. Actors有类似消息的mailbox / queue;

我们认为编写正确的并行、容错和可伸缩的程序是非常困难的。大多数的时候是由于我们使用了错误的工作和错误的抽象层级。Akka就是为了改变此而来。Akka使用Actor模型我们提升了抽象层级,提供了一个编写可伸缩、有弹性和响应式的程序--访问ReactiveManifesto看更多细节。容错方面我们采用“随它崩溃”的模型,这种模型在电信行业应用得很成功,用此模型我们可以构建自愈且永不停止的程序。Actors 也提供了清晰的分布式程序的抽象,和构建真正的可伸缩容错程序的基础。

akka学习笔记:https://www.iteblog.com/archives/1154.html

akka与netty对比:https://www.cnblogs.com/WangBoBlog/p/7843688.html

为什么play在之后的版本使用akka作为默认的服务后端,而将netty放到二线了呢?

Hi everyone,

I wanted to answer a few questions I have heard about Akka HTTP in Play 2.6. Hopefully this should clear up any concerns people have.

Why is Play switching to Akka HTTP as the default server?

Play is switching for a few reasons. Play already uses Akka and Akka streams internally, and the model Akka HTTP uses for representing requests and responses is much closer to Play's. Some of the improvements we plan to make in 3.0 will bring them closer together. We are optimistic about the Akka HTTP project and where it's headed in terms of features and performance.

//是说akka和play更加贴切

While both Netty and Play are active projects, it's much easier for us to work with the Akka team. This is in part due to shared philosophy and goals but also due to the fact that both teams work for Lightbend. This improved communication will help us implement new features and fix bugs and security issues more quickly.

//akka和play合作更为快捷

What's the difference in performance?

//性能有啥不一样呢

Currently we have done no optimization, so the Akka server on 2.6.0-M1 is actually slower than the Netty server. This is expected. We are working with the Akka team to bring the performance to the same level, or hopefully better. You should see the improvements on prune as we continue this work.

//akka还没怎么优化,性能上来说势必netty要慢的,但还是说他们和akka的团队合作的更为密切,以后会改的。。

Our contributor Christian Schmitt also published a gist with nice benchmarks showing akka-http performance (without Play) actually exceeds that of play-netty-server in his test case, in terms of both latency and bytes transferred. Based on this and similar benchmarks we have done, we expect to see comparable performance to Netty once we've removed the unnecessary overhead introduced in the conversion between Play and Akka HTTP models.

//开始说服,有人测试,akka在不用play的时候,性能实际上是超过play使用netty的;

Does Play still support the Netty server backend?

Yes. We will continue supporting both Netty and Akka HTTP backends for the foreseeable future, but will prioritize new features on Akka HTTP.

If you want to switch back to the Netty server, please see the Netty server documentation.

What about HTTP/2?

HTTP/2 is coming as part of the improvements being made to the Akka HTTP server and will be included in a future milestone. We are interested in implementing it on Netty as well, but it's not a priority for the 2.6.0 release. We'd gladly accept contributions from the community, though.

//所以没啥别的原因,就是我和akka关系好,我用这个能更好的做优化做更新开发。。

而akka在在开发中几乎把所有分布式通信(即使是单机内分布式)中会出现的问题全部都交给开发人员自己考虑和设计,难以驾驭。

  • 全堆栈 

Play为你提供多种条件,例如开发框架、运行环境。可以理解为,你无需再下载别的软件,它全包括做一个网

站所需的所有环境,除了开发工具之外。

  • 动态编译

修改源码,刷新网页,Done。不需要重新编译,发布和重启服务器。动态的编译更改的项目文件。

解决了SSH在开发过程中,频繁地刷新项目,提高了开发的效率。

  • 异步性

基于非阻塞的IO模型,play允许创建基于long polling和WebSocket的现代网页应用。

  • 快速纠错

当错误发生的时候,play直接在网页中展示出的错误源代码,以及错误源代码所在的行号,让程序员可以完全摆脱SSH的调试工具Junit。

  • Rails 的思想(约定优于配置

更少的配置文件;更少的代码;开发效率的大提速。

我们只需要按照其约定的结构去组织我们的代码就可以很轻松地实现一个 Web 应用。

ebean框架见闻

Ebean是一个使用纯Java实现的开源ORM框架。 Bean使用JPA注释(@entity, @OneToMany等Java注释)对实体进行映射。Ebean力求让使用最简单的API帮助开发者从数据库获取有用的数据信息。

学习资料:Ebean的官网 www.avaje.org/

ebean使用JPQL(Java Persistence Query Language),JPQL与SQL的区别就是SQL是面向对象关系数据库,他操作的是数据表和数据列,而JPQL操作的对象是实体对象和实体属性。

对比几个不同的数据持久化框架

Hibernate和Mybatis是使用最多的两个主流框架,而JOOQ、Ebean等小众框架则知道的人不多,但也有很多独特的优点;

JPA是一组Java持久层Api的规范,Spring Data JPA是JPA Repository的实现,本来和Hibernate、Mybatis、JOOQ之类的框架不在同一个层次上,但引入Spring Data JPA之类框架之后,我们会直接使用JPA的API查询更新数据库,就像我们使用Mybatis一样,所以这里也把JPA和其他框架放在一起进行比较。

同样,JDBC和其他框架也在同一层次,位于所有持久框架的底层,但我们有时候也会直接在项目中使用JDBC,而Spring JDBC Template部分消除了使用JDBC的繁琐细节,降低了使用成本,使得我们更加愿意在项目中直接使用JDBC。

持久化框架对比:https://segmentfault.com/a/1190000018472572

 

react框架

会写代码,组件之间获取数据就成了 = =!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值