粗粒度与细粒度

发布于 2024-09-24 06:48:02 字数 1827 浏览 4 评论 0原文

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(11

旧城烟雨 2024-10-01 06:48:02

来自维基百科(粒度)

粒度是指
系统被分解成小的
部件,无论是系统本身还是它的
描述或观察。它是
较大实体的程度
细分。例如,一个院子坏了
英寸的粒度比
一码分成英尺。

粗粒度系统包括
更少、更大的组件
细粒度系统;粗粒度的
系统的描述涉及大
细粒度的子组件
描述涉及较小的组件
其中较大的由其中组成。

From Wikipedia (granularity):

Granularity is the extent to which a
system is broken down into small
parts, either the system itself or its
description or observation. It is the
extent to which a larger entity is
subdivided. For example, a yard broken
into inches has finer granularity than
a yard broken into feet.

Coarse-grained systems consist of
fewer, larger components than
fine-grained systems; a coarse-grained
description of a system regards large
subcomponents while a fine-grained
description regards smaller components
of which the larger ones are composed.

醉南桥 2024-10-01 06:48:02

简单来说

  • 粗粒度 - 比细粒度的大型子组件更大的组件。只需将一个或多个细粒度的服务包装在一起,形成一个更粗粒度的操作。
  • 细粒度 - 由较大组件组成的较小组件,较低级别的服务

最好有更多的粗粒度服务操作,这些操作由细粒度操作组成

在此处输入图像描述

In simple terms

  • Coarse-grained - larger components than fine-grained, large subcomponents. Simply wraps one or more fine-grained services together into a more coarse­-grained operation.
  • Fine-grained - smaller components of which the larger ones are composed, lower­level service

It is better to have more coarse-grained service operations, which are composed by fine-grained operations

enter image description here

鸩远一方 2024-10-01 06:48:02

粗粒度:一些对象保存了大量相关数据,这就是服务具有更广泛功能范围的原因。示例:单个“帐户”对象保存客户姓名、地址、帐户余额、开户日期、最后更改日期等。
因此:增加了设计复杂性,减少了各种操作的单元数量

细粒度:更多的对象,每个对象持有更少的数据,这就是服务的功能范围更窄的原因。示例:Account 对象保存余额,Customer 对象保存姓名和地址,AccountOpenings 对象保存开仓日期等。
因此:降低了设计复杂性,增加了用于各种服务操作的单元数量。
这些是这些对象之间定义的关系。

Coarse-grained: A few ojects hold a lot of related data that's why services have broader scope in functionality. Example: A single "Account" object holds the customer name, address, account balance, opening date, last change date, etc.
Thus: Increased design complexity, smaller number of cells to various operations

Fine-grained: More objects each holding less data that's why services have more narrow scope in functionality. Example: An Account object holds balance, a Customer object holds name and address, a AccountOpenings object holds opening date, etc.
Thus: Decreased design complexity , higher number of cells to various service operations.
These are relationships defined between these objects.

弥枳 2024-10-01 06:48:02

另一种理解方法是考虑进程和线程之间的通信。进程借助套接字、信号处理程序、共享内存、信号量和文件等粗粒度通信机制进行通信。另一方面,线程可以访问属于进程的共享内存空间,这允许它们应用更细粒度的通信机制。

来源:Java 并发实践

One more way to understand would be to think in terms of communication between processes and threads. Processes communicate with the help of coarse grained communication mechanisms like sockets, signal handlers, shared memory, semaphores and files. Threads, on the other hand, have access to shared memory space that belongs to a process, which allows them to apply finer grain communication mechanisms.

Source: Java concurrency in practice

倾城月光淡如水﹏ 2024-10-01 06:48:02

在服务上下文中:

http://en.wikipedia.org/wiki/Service_Granularity_Principle

根据定义,粗粒度的服务操作具有更广泛的范围
比细粒度的服务更好,尽管这些术语是相对的。这
前者通常需要增加设计复杂性,但可以减少
完成任务所需的调用次数。

细粒度的服务接口与聊天接口大致相同。

In the context of services:

http://en.wikipedia.org/wiki/Service_Granularity_Principle

By definition a coarse-grained service operation has broader scope
than a fine-grained service, although the terms are relative. The
former typically requires increased design complexity but can reduce
the number of calls required to complete a task.

A fine grained service interface is about the same like chatty interface.

南烟 2024-10-01 06:48:02

就文本文件之类的数据集而言,粗粒度意味着我们可以转换整个数据集,但不能转换数据集上的单个元素,而细粒度意味着我们可以转换数据集上的单个元素。

In term of dataset like a text file ,Coarse-grained meaning we can transform the whole dataset but not an individual element on the dataset While fine-grained means we can transform individual element on the dataset.

美胚控场 2024-10-01 06:48:02

粗粒度和细粒度都是考虑优化一些服务。但区别在于级别。我喜欢用例子来解释,你会很容易理解。

细粒度:比如我有findbyId、findbyCategry、findbyName……等100个服务。为什么我们不能提供 find(id、category、name...等等),而不是那么多服务。这样我们就可以减少服务。这只是一个例子,但目标是如何优化服务数量。

粗粒度:例如,我有100个客户端,每个客户端都有自己的一组100个服务。所以我必须提供100*100的全服务。这是非常困难的。相反,我所做的是,我将适用于大多数客户的所有通用服务识别为一个服务集并单独保留。例如,在 100 个服务中,有 50 个服务是常见的。所以我只需要管理100*50 + 50。

Coarse-grained and Fine-grained both think about optimizing a number of servicess. But the difference is in the level. I like to explain with an example, you will understand easily.

Fine-grained: For example, I have 100 services like findbyId, findbyCategry, findbyName...... so on. Instead of that many services why we can not provide find(id, category, name....so on). So this way we can reduce the services. This is just an example, but the goal is how to optimize the number of services.

Coarse-grained: For example, I have 100 clients, each client have their own set of 100 services. So I have to provide 100*100 total services. It is very much difficult. Instead of that what I do is, I identify all common services which apply to most of the clients as one service set and remaining separately. For example in 100 services 50 services are common. So I have to manage 100*50 + 50 only.

傲影 2024-10-01 06:48:02

粗粒度并不总是意味着更大的组件,如果你按照“粗”这个词的字面意思来看,它意味着严酷或不合适。例如,在软件项目管理中,如果将一个小系统分解为几个组件,这些组件大小相同,但复杂性和功能各不相同,这可能会导致粗粒度。相反,对于细粒度的细分,您可以根据每个组件提供的功能的内聚性来划分组件。

Coarse-grained granularity does not always mean bigger components, if you go by literally meaning of the word coarse, it means harsh, or not appropriate. e.g. In software projects management, if you breakdown a small system into few components, which are equal in size, but varies in complexities and features, this could lead to a coarse-grained granularity. In reverse, for a fine-grained breakdown, you would divide the components based on their cohesiveness of the functionalities each component is providing.

尤怨 2024-10-01 06:48:02

粗粒度和细粒度。这两种模式都定义了如何共享核心
多个 Spark 任务之间。顾名思义,细粒度模式是
负责在更细粒度的级别上共享核心。 细粒度模式已被 Spark 弃用,并将很快被删除。

coarse grained and fine grained. Both of these modes define how the cores are shared
between multiple Spark tasks. As the name suggests, fine-grained mode is
responsible for sharing the cores at a more granular level. Fine-grained mode has been deprecated by Spark and will soon be removed.

玩世 2024-10-01 06:48:02

与细粒度服务相比,科西嘉粒度服务提供更广泛的功能。根据业务领域,可以创建单个服务来服务单个业务单元,或者如果子单元很大程度上彼此独立,则可以创建专门的多个细粒度服务。
粗粒度服务可能会变得更加困难,由于其规模而不太适应变化,而细粒度服务可能会引入管理多个服务的额外复杂性。

Corse-grained services provides broader functionalities as compared to fine-grained service. Depending on the business domain, a single service can be created to serve a single business unit or specialised multiple fine-grained services can be created if subunits are largely independent of each other.
Coarse grained service may get more difficult may be less adaptable to change due to its size while fine-grained service may introduce additional complexity of managing multiple services.

守护在此方 2024-10-01 06:48:02

粒度在存储空间非常重要的大规模数据时具有重要的应用。

根据牛津词典,粒度的含义是 -

“一组数据的详细程度或程度。”

根据剑桥词典 -

“信息中包含很多小细节,使你可以非常清楚地了解正在发生的事情”

所以从这个词的具体含义来看,它是一种连续过程的数据划分。

更细的粒度由小区间划分组成,从而可以实现详细的表示。
另一方面,较粗的粒度就是较大的帧间隔,这样可以节省存储空间。

两种粒度的使用是特定于应用程序的。

例如,如果我们有一个应用程序,其中最近的时间信息比旧的信息更重要。对于最近数据的详细表示,可以通过更细的粒度找到,而对于较旧的数据表示,我们可以使用较粗的粒度

Granularity has an important application while storing large scale data where space is very important.

The meaning of granularity according to Oxford dictionary is -

"The scale or level of detail in a set of data."

According to Cambridge dictionary -

"A lot of small details included in information, making it possible for you to understand very clearly what is happening"

So from the word specific meaning, it is some kind of partition of data for a continuous process.

Finer granularity consists of small interval partition, so that detailed representation can be achieved.
On the other hand, coarser granularity is larger frame interval, so that it can save storage.

Uses of two types of granularity is application specific.

For example- If we have an application, where recent time information is more important than the older information. For detailed representation of recent data can be found by finer granularity, while for older data representation we can use coarser granularity.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文