
# 配置Spark多租户模式
#### 操作场景
JDBCServer多主实例方案中，JDBCServer的实现使用YARN-Client模式，但YARN资源队列只有一个，为了解决这种资源局限的问题，引入了多租户模式。
多租户模式是将JDBCServer和租户绑定，每一个租户对应一个或多个JDBCServer，一个JDBCServer只给一个租户提供服务。不同的租户可以配置不同的Yarn队列，从而达到资源隔离，且JDBCServer根据需求动态启动，可避免浪费资源。
#### 配置描述
1. 登录FusionInsight Manager系统。 
   详细操作请参考[访问集群Manager](https://support.huaweicloud.com/cmpntguide-lts-mrs/mrs_01_2124.html)。
   
   

2. 选择"集群 \> 服务 \> Spark2x/Spark \> 配置"，单击"全部配置"，搜索并调整以下参数。 
   表1参数说明 
   | **参数**                                                | **说明**                                                                                                                                                                                                                                                                                                                                                                                                                   | 配置示例   |
   |:---|:---|:---|
   | spark.proxyserver.hash.enabled                        | 是否使用Hash算法连接ProxyServer。 - true为使用Hash算法，使用多租户模式时，该参数需配置为true。  - false为使用随机连接，多主实例模式，配置为false。   该参数修改后需要重新下载客户端。 | true   |
   | spark.thriftserver.proxy.enabled                      | 是否使用多租户模式。 - false表示使用多实例模式。  - true表示使用多租户模式。                                                                     | true   |
   | spark.thriftserver.proxy.maxThriftServerPerTenancy    | 多租户模式下，一个租户可启动JDBCServer实例的最大个数。 取值范围：1\~2147483647                                                                                                                                                                                                                                                                                                                                         | 2      |
   | spark.thriftserver.proxy.maxSessionPerThriftServer    | 多租户模式下，单个JDBCServer实例的session数量超过该值时，如果租户的JDBCServer最大实例数量没超过限制，则启动新的JDBCServer，否则输出警告日志。 取值范围：1\~2147483647                                                                                                                                                                                                                                                            | 200    |
   | spark.thriftserver.proxy.sessionWaitTime              | 多租户模式下，当JDBCServer的session连接数为0时，停止JDBCServer前的等待时间，单位：毫秒。 取值范围：1\~2147483647                                                                                                                                                                                                                                                                                           | 180000 |
   | spark.thriftserver.proxy.sessionThreshold             | 多租户模式下，当JDBCServer的session使用率（公式：当前session数 / (spark.thriftserver.proxy.maxSessionPerThriftServer \* 当前JDBCServer个数)）达到阈值时，自动新增JDBCServer。                                                                                                                                                                                                                                                                               | 100    |
   | spark.thriftserver.proxy.healthcheck.period           | 多租户模式下，JDBCServer代理检查JDBCServer健康状态周期，单位：毫秒。 取值范围：1\~2147483647                                                                                                                                                                                                                                                                                                         | 120000 |
   | spark.thriftserver.proxy.healthcheck.recheckTimes     | 多租户模式下，JDBCServer代理检查JDBCServer健康状态失败后重试次数。 取值范围：1\~2147483647                                                                                                                                                                                                                                                                                                          | 6      |
   | spark.thriftserver.proxy.healthcheck.waitTime         | 多租户模式下，JDBCServer代理发送健康检查，等待JDBCServer响应的超时时间，单位：毫秒。 取值范围：1\~2147483647                                                                                                                                                                                                                                                                                                 | 10000  |
   | spark.thriftserver.proxy.session.check.interval       | 多租户模式下，JDBCServer代理检查session的周期。                                                                                                                                                                                                                                                                                                                                                                                         | 6h     |
   | spark.thriftserver.proxy.idle.session.timeout         | 多租户模式下，JDBCServer代理session的空闲超时时间。如果在这段时间内没有做任何操作，session会被关闭。                                                                                                                                                                                                                                                                                                                                                           | 7d     |
   | spark.thriftserver.proxy.idle.session.check.operation | 多租户模式下，JDBCServer代理session的过期是否要判断该session上还存在operation。 - true：JDBCServer代理session的过期启动判断该session上还存在operation。  - false：JDBCServer代理session的过期不启动判断该session上还存在operation。                                 | true   |
   | spark.thriftserver.proxy.idle.operation.timeout       | 多租户模式下，operation的超时时间。如果operation超时，operation会被关闭。                                                                                                                                                                                                                                                                                                                                                                       | 5d     |
   | hive.spark.client.server.connect.timeout              | 多租户模式下，客户端连接超时时间。                                                                                                                                                                                                                                                                                                                                                                                                        | 5min   |
      
   
   

3. 修改参数配置后，单击"保存"，根据界面提示操作后，等待配置保存成功。
4. Spark服务端配置更新后，如果"配置状态"为"配置过期"，则需重启组件以使配置生效。 
   图1修改Spark配置   
   ![](https://support.huaweicloud.com/cmpntguide-lts-mrs/zh-cn_image_0000002305123232.png "点击放大")
   在Spark服务概览页面，选择"更多 \> 重启服务/滚动重启服务"，验证管理员密码后，等待服务重启成功。
   ![](https://support.huaweicloud.com/cmpntguide-lts-mrs/public_sys-resources/warning_3.0-zh-cn.png)
   组件重启期间将无法对外提供服务，可能会影响集群的上层业务正常运行，请在业务空闲期或确认操作无影响后再执行本操作。
   
   
 
#### 相关文档
Spark多租户更多介绍请参考[Spark2x多租户](https://support.huaweicloud.com/productdesc-mrs/mrs_08_007104.html)。
