Giter Site home page Giter Site logo

请教一下性能的问题 about hprose-php HOT 8 CLOSED

hprose avatar hprose commented on May 3, 2024
请教一下性能的问题

from hprose-php.

Comments (8)

andot avatar andot commented on May 3, 2024

可以安装 hprose-pecl 来提高序列化、反序列化的性能。这个对于数据比较大的复杂数据性能提升很明显。

然后就是用 hprose-swoole 来做服务器,可以避免创建多个客户端,只需要一个客户端就可以代理所有请求了。

from hprose-php.

forgottener avatar forgottener commented on May 3, 2024

需要在每台服务器上安装hprose-pecl、swoole扩展吗?我用hprose的出发点是为了避免其他项目的服务器需要安装各种扩展

from hprose-php.

andot avatar andot commented on May 3, 2024

用到 hprose 的服务器安装 hprose-pecl,使用 php-fpm 的客户端不需要安装 swoole 扩展,这两个扩展安装都很容易直接使用:

pecl install hprose
pecl install swoole

命令安装就可以了。

from hprose-php.

forgottener avatar forgottener commented on May 3, 2024

swoole的客户端不装swoole扩展好像不行吧?你的意思是做http接口给其他项目调用?

from hprose-php.

andot avatar andot commented on May 3, 2024

swoole的客户端只能用于命令行下面,在 php-fpm 下面只能使用 hprose-php 下面的客户端,这里面也有 TCP 客户端的。hprose-php 的 TCP 客户端(这个客户端不需要扩展)同样可以连接 swoole 的 TCP 服务器。

from hprose-php.

forgottener avatar forgottener commented on May 3, 2024

多谢大神耐心指导,"用 hprose-swoole 来做服务器,可以避免创建多个客户端,只需要一个客户端就可以代理所有请求了。" 我不太明白这句话后面的意思,只做一个客户端用来代理请求,那么这些请求是怎么到这个客户端的?用http服务RESTful吗? 我有这样的业务场景:
首先是一台提供RPC方法的hprose服务器A(192.168.1.1), 然后有X,Y,Z 3个项目,3个项目是对用户开放的网站服务,比方说X,Y,Z有个登录场景都需要调用A服务器的a()方法,那么我目前没想明白的地方是,X,Y,Z都需要通过$hprose = new Hprose\Socket\Client("tcp://192.168.1.1:1314", false) 来得到一个$hprose客户端,再通过'$hprose->a();'来调用A服务器的a()方法,这样的话X,Y,Z项目中,每一次用户通过http请求进来做登录时都需要new hprose的客户端出来吧?
你提到的代理所有请求是怎么做到的?是再在服务器A(192.168.1.1)单独开启一个http服务(http://192.168.1.1/a))吗?让X,Y,Z通过请求http://192.168.1.1/a服务的RESTful api,然后由A再去执行a()方法? 那这种情况下X,Y,Z项目都不需要引入hprose了,这不像RPC了吧,这感觉是SOA接口了

from hprose-php.

andot avatar andot commented on May 3, 2024

你的意思是这个对吧:

+---------+      +------------+      +---------------+
| Browser |----->| Web Server |----->| Hprose Server |
+---------+      +------------+      +---------------+

你的 hprose 客户端是在 Web Server 上。

其中 Hprose Server 如果是基于 swoole 的,那么这个服务器会很快,使用 TCP 方式发布服务就可以。

而 Web Server 如果本身也用 swoole 来实现的话,那么这部分就可以用 hprose-swoole 的客户端来做,这种情况下,这个地方的客户端只需要一个就可以了。

而如果 Web Server 不是基于 swoole 来实现的,而是使用 nginx、IIS 等服务加 php 来实现的话,那么就只能使用 hprose-php 的 Hprose\Socket\Client 了,这种情况下,确实只能每个请求创建一次客户端,但是如果你创建的是 hprose 的异步客户端的话,那么它跟 hprose 服务器的连接是 STREAM_CLIENT_PERSISTENT 的,所以在多请求之间也可以被复用,而且异步客户端支持全双工模式,可以在单个连接上同时进行多个调用,比同步客户端要高效。所以如果想要提高效率,可以考虑使用 Hprose\Socket\Client 异步客户端模式,结合 hprose 中的协程,使用异步客户端的程序代码也不会太难写。

一般来说,如果你传输的数据比较复杂,那么传输慢的主要原因是序列化和反序列化比较慢,只需要安装一下 hprose-pecl 扩展就可以解决。

from hprose-php.

forgottener avatar forgottener commented on May 3, 2024

明白了,太谢谢你了

from hprose-php.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.