如何在所有Azure功能实例之间共享对象状态 [英] How To Share object state across all Azure Function Instances

查看:39
本文介绍了如何在所有Azure功能实例之间共享对象状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个C#Azure Function应用程序(消费计划),它可以动态扩展,即根据负载添加新实例,现在我们有了一个对象,该对象需要在此Azure Function的所有实例中使用,因为该对象很复杂(有代表)我无法序列化放置在外部缓存上,以便所有实例都可以从那里访问它,请提出处理这种情况的最佳方法.

We have a C# Azure Function App (consumption plan) which scales dynamically i.e new instances are added depending on the load, now we have an object which needs to be used across all instances of this Azure Function, as the object is complex (has delegates) I cannot serialize to put on an external cache so that all instances can access it from there, please suggest the best way to handle this scenario.

推荐答案

您的问题有一些根本矛盾的地方:您不能同时具有以下两个方面:a)可扩展到许多计算机的函数;b)所有实例共享内存对象,就像它们在单台计算机上运行一样.它的发展也相反:无服务器意味着如果没有人使用您的功能,则所有基础架构都可以关闭(从而为您省钱)-但这隐含意味着您将失去内存中状态,需要能够序列化它.

There's something fundamentally contradictory in your question: you can't have both a) a function that scales to many machines; b) all instances sharing in-memory objects as if they were running on a single machine. It goes the other way too: serverless means that if nobody is using your function, all infrastructure can be shut down (hence saving you money) - but that implicitly means you'd lose your in-memory state and need to be able to serialize it.

最小化共享状态,使其可序列化(存在用于处理诸如委托[1]之类的模式)的功能,并使用外部存储(Azure Storage或Redis之类的缓存).

Minimize the shared state, make it serializable (there are patterns for dealing with things like delegates [1]), and use external storage (Azure Storage, or a cache like Redis).

[1]对于委托人,一个技巧是维护代表的句柄字典,然后序列化该句柄.同样,对于多态,您可以序列化类型名称.

[1] For delegates, one trick is to maintain a dictionary of handles to delegates, and then serialize the handle. Similarly, for polymorphism, you might serialize the type name.

这篇关于如何在所有Azure功能实例之间共享对象状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆