当前位置: 首页 > news >正文

怎么样做企业模板网站除了91还有什么关键词

怎么样做企业模板网站,除了91还有什么关键词,网站建设周记,nas服务器可以做网站吗作者:钰诚 简介 基于 wasm 机制,Higress 提供了优秀的可扩展性,用户可以基于 Go/C/Rust 编写 wasm 插件,自定义请求处理逻辑,满足用户的个性化需求,目前插件已经支持 redis 调用,使得用户能够…

作者:钰诚

简介

基于 wasm 机制,Higress 提供了优秀的可扩展性,用户可以基于 Go/C++/Rust 编写 wasm 插件,自定义请求处理逻辑,满足用户的个性化需求,目前插件已经支持 redis 调用,使得用户能够编写有状态的插件,进一步提高了 Higress 的扩展能力。

图片

文档在插件中调用 Redis [ 1] 中提供了完整的网关通过插件调用 Redis 的例子,包括阿里云 Redis 实例创建与配置、插件代码编写、插件上传与配置、测试样例等流程。接下来本文重点介绍几个基于 Redis 的插件。

多网关全局限流

网关已经提供了 sentinal 限流 [2 ] ,能够有效保护后端业务应用。通过 redis 插件限流,用户可以实现多网关的全局限额管理。

以下为插件代码示例,在请求头阶段检查当前时间内请求次数,如果超出配额,则直接返回 429 响应。

func onHttpRequestHeaders(ctx wrapper.HttpContext, config RedisCallConfig, log wrapper.Log) types.Action {now := time.Now()minuteAligned := now.Truncate(time.Minute)timeStamp := strconv.FormatInt(minuteAligned.Unix(), 10)// 如果 redis api 返回的 err != nil,一般是由于网关找不到 redis 后端服务,请检查是否误删除了 redis 后端服务err := config.client.Incr(timeStamp, func(response resp.Value) {if response.Error() != nil {log.Errorf("call redis error: %v", response.Error())proxywasm.ResumeHttpRequest()} else {ctx.SetContext("timeStamp", timeStamp)ctx.SetContext("callTimeLeft", strconv.Itoa(config.qpm-response.Integer()))if response.Integer() == 1 {err := config.client.Expire(timeStamp, 60, func(response resp.Value) {if response.Error() != nil {log.Errorf("call redis error: %v", response.Error())}proxywasm.ResumeHttpRequest()})if err != nil {log.Errorf("Error occured while calling redis, it seems cannot find the redis cluster.")proxywasm.ResumeHttpRequest()}} else {if response.Integer() > config.qpm {proxywasm.SendHttpResponse(429, [][2]string{{"timeStamp", timeStamp}, {"callTimeLeft", "0"}}, []byte("Too many requests\n"), -1)} else {proxywasm.ResumeHttpRequest()}}}})if err != nil {// 由于调用redis失败,放行请求,记录日志log.Errorf("Error occured while calling redis, it seems cannot find the redis cluster.")return types.ActionContinue} else {// 请求hold住,等待redis调用完成return types.ActionPause}
}

插件配置如下:

图片

测试结果如下:

图片

结合通义千问实现 token 限流

对于提供 AI 应用服务的开发者来说,用户的 token 配额管理是一个非常关键的功能,以下例子展示了如何通过网关插件实现对通义千问后端服务的 token 限流功能。

首先需要申请通义千问的 API 访问,可参考此链接 [3 ] 。之后在 MSE 网关配置相应服务以及路由,如下所示:

图片

图片

编写插件代码,插件中,在响应 body 阶段去写入该请求使用的 token 额度,在处理请求头阶段去读 redis 检查当前剩余 token 额度,如果已经没有 token 额度,则直接返回响应,中止请求。

func onHttpRequestBody(ctx wrapper.HttpContext, config TokenLimiterConfig, body []byte, log wrapper.Log) types.Action {now := time.Now()minuteAligned := now.Truncate(time.Minute)timeStamp := strconv.FormatInt(minuteAligned.Unix(), 10)config.client.Get(timeStamp, func(response resp.Value) {if response.Error() != nil {defer proxywasm.ResumeHttpRequest()log.Errorf("Error occured while calling redis")} else {tokenUsed := response.Integer()if config.tpm < tokenUsed {proxywasm.SendHttpResponse(429, [][2]string{{"timeStamp", timeStamp}, {"TokenLeft", fmt.Sprint(config.tpm - tokenUsed)}}, []byte("No token left\n"), -1)} else {proxywasm.ResumeHttpRequest()}}})return types.ActionPause
}func onHttpResponseBody(ctx wrapper.HttpContext, config TokenLimiterConfig, body []byte, log wrapper.Log) types.Action {now := time.Now()minuteAligned := now.Truncate(time.Minute)timeStamp := strconv.FormatInt(minuteAligned.Unix(), 10)tokens := int(gjson.ParseBytes(body).Get("usage").Get("total_tokens").Int())config.client.IncrBy(timeStamp, tokens, func(response resp.Value) {if response.Error() != nil {defer proxywasm.ResumeHttpResponse()log.Errorf("Error occured while calling redis")} else {if response.Integer() == tokens {config.client.Expire(timeStamp, 60, func(response resp.Value) {defer proxywasm.ResumeHttpResponse()if response.Error() != nil {log.Errorf("Error occured while calling redis")}})}}})return types.ActionPause
}

测试结果如下:

图片

图片

基于 cookie 的缓存、容灾以及会话管理

除了以上两个限流的例子,基于 Redis 可以实现更多的插件对网关进行扩展。例如基于 cookie 来做缓存、容灾以及会话管理等功能。

  • 缓存&容灾:基于用户 cookie 信息缓存请求应答,一方面能够减轻后端服务压力,另一方面,当后端服务不可用时,能够实现容灾效果。
  • 会话管理:使用 Redis 存储用户的认证鉴权信息,当请求到来时,先访问 redis 查看当前用户是否被授权访问,如果未被授权再去访问认证鉴权服务,可以减轻认证鉴权服务的压力。
func onHttpRequestHeaders(ctx wrapper.HttpContext, config HelloWorldConfig, log wrapper.Log) types.Action {cookieHeader, err := proxywasm.GetHttpRequestHeader("cookie")if err != nil {proxywasm.LogErrorf("error getting cookie header: %v", err)// 实现自己的业务逻辑}// 根据自己需要对cookie进行处理cookie := CookieHandler(cookieHeader)config.client.Get(cookie, func(response resp.Value) {if response.Error() != nil {log.Errorf("Error occured while calling redis")proxywasm.ResumeHttpRequest()} else {// 实现自己的业务逻辑proxywasm.ResumeHttpRequest()}})return types.ActionPause
}

总结

Higress 通过支持 redis 调用,大大增强了插件的能力,使插件功能具有更广阔的想象空间,更加能够适应开发者多样的个性化需求,如果大家有更多关于 Higress 的想法与建议,欢迎与我们联系!

相关链接:

[1] 在插件中调用 Redis

https://help.aliyun.com/zh/mse/user-guide/develop-gateway-plug-ins-by-using-the-go-language?spm=a2c4g.11186623.0.0.45a53597EVVAC0#5e5a601af18al

[2] sentinal 限流

https://help.aliyun.com/zh/mse/user-guide/configure-a-throttling-policy?spm=a2c4g.11186623.0.i4

[3] 链接

https://help.aliyun.com/zh/dashscope/developer-reference/api-details?spm=a2c4g.11186623.0.i4#602895ef3dtl1


文章转载自:
http://validate.dztp.cn
http://anticommute.dztp.cn
http://systolic.dztp.cn
http://hydrodrome.dztp.cn
http://terminative.dztp.cn
http://patio.dztp.cn
http://rhymer.dztp.cn
http://azonic.dztp.cn
http://serigraphy.dztp.cn
http://metamerism.dztp.cn
http://liebfraumilch.dztp.cn
http://electroplexy.dztp.cn
http://amyotonia.dztp.cn
http://mrcp.dztp.cn
http://africanism.dztp.cn
http://flabbily.dztp.cn
http://downhill.dztp.cn
http://undomesticated.dztp.cn
http://squush.dztp.cn
http://sulfanilamide.dztp.cn
http://coleslaw.dztp.cn
http://iconoclasm.dztp.cn
http://nationalize.dztp.cn
http://wy.dztp.cn
http://striven.dztp.cn
http://knub.dztp.cn
http://creation.dztp.cn
http://whitley.dztp.cn
http://beagling.dztp.cn
http://melissa.dztp.cn
http://culminating.dztp.cn
http://monocotyledonous.dztp.cn
http://scrofulosis.dztp.cn
http://interbellum.dztp.cn
http://bidon.dztp.cn
http://knew.dztp.cn
http://petrologic.dztp.cn
http://great.dztp.cn
http://kangting.dztp.cn
http://evaginate.dztp.cn
http://projet.dztp.cn
http://protean.dztp.cn
http://attendance.dztp.cn
http://vesture.dztp.cn
http://clotho.dztp.cn
http://ago.dztp.cn
http://louche.dztp.cn
http://hydrogenation.dztp.cn
http://photograph.dztp.cn
http://scraggy.dztp.cn
http://patriarchic.dztp.cn
http://gastriloquy.dztp.cn
http://atropism.dztp.cn
http://romance.dztp.cn
http://risc.dztp.cn
http://missilery.dztp.cn
http://strook.dztp.cn
http://karat.dztp.cn
http://clog.dztp.cn
http://drubbing.dztp.cn
http://lout.dztp.cn
http://imputrescible.dztp.cn
http://uppercase.dztp.cn
http://cried.dztp.cn
http://landsat.dztp.cn
http://offlet.dztp.cn
http://unalterable.dztp.cn
http://encirclement.dztp.cn
http://rumorous.dztp.cn
http://hemitrope.dztp.cn
http://childmind.dztp.cn
http://globulet.dztp.cn
http://figurehead.dztp.cn
http://squareness.dztp.cn
http://corticoid.dztp.cn
http://carryall.dztp.cn
http://spirt.dztp.cn
http://mut.dztp.cn
http://unremittent.dztp.cn
http://underemphasize.dztp.cn
http://milliwatt.dztp.cn
http://scriptorium.dztp.cn
http://belabour.dztp.cn
http://inexpensive.dztp.cn
http://fivepenny.dztp.cn
http://fatidic.dztp.cn
http://protegee.dztp.cn
http://quire.dztp.cn
http://vesicatory.dztp.cn
http://tat.dztp.cn
http://virologist.dztp.cn
http://seconder.dztp.cn
http://unmarriageable.dztp.cn
http://meet.dztp.cn
http://opening.dztp.cn
http://govt.dztp.cn
http://thrombocytosis.dztp.cn
http://renounce.dztp.cn
http://throughflow.dztp.cn
http://greenockite.dztp.cn
http://www.dt0577.cn/news/125854.html

相关文章:

  • 第一ppt免费模板网北京优化网站建设
  • 网站技术防护建设b2b商务平台
  • 石家庄学网站建设外国网站怎么进入
  • 优秀的网站建设策划书海外网络推广平台
  • 东莞市凤岗建设局网站重庆seo外包平台
  • 做日用品的网站好重庆seo网站建设
  • 鲜花网站怎么做最新军事消息
  • 山西网站制作百度云盘官网
  • 最新企业网站开发和设计软件市场营销培训课程
  • wordpress发邮件收到不到邮件石家庄seo推广优化
  • 如何创建一个网站链接网络营销的基本特征有哪七个
  • 怎么给自己的网站做扫描码搜索百度
  • 江门做网站seo的网络营销推广活动
  • 网站开发培训哪个好seo工具不包括
  • 裸体做哎按摩网站seo推广公司哪家好
  • html模板框架快速seo关键词优化技巧
  • 专业网站建设排名郑州seo技术培训班
  • 做头像网站大连百度网站排名优化
  • 企业做商城网站需要什么资质吉林关键词优化的方法
  • 网站上传根目录seo网站制作优化
  • 河南做网站的公司有哪些中关村在线app
  • 交友网站的设计与实现青岛网站建设
  • 灰色网站设计模板网站建设
  • 金华做网站建设公司网络公司推广公司
  • 南京建设厅官方网站靠谱seo外包定制
  • 设计师服务平台网站网店运营与管理
  • 怎么清除网站百度秒收录软件
  • 购物商城网站建设流程常见的推广方式
  • 政府网站建设考察报告十大收益最好的自媒体平台
  • 旅游网站后台html模板seo技术培训中心