Closed drew2a closed 1 year ago
For each of the components there are two types of objects:
My main notes for interfaces are:
class PopularityComponent(Component):
enable_in_gui_test_mode = True
community: PopularityCommunity
@classmethod
def should_be_enabled(cls, config: TriblerConfig):
return config.ipv8.enabled and config.popularity_community.enabled
# this method should not be a part of component. It should be a part of the tests.
@classmethod
def make_implementation(cls, config: TriblerConfig, enable: bool):
if enable:
from tribler_core.components.implementation.popularity import PopularityComponentImp
return PopularityComponentImp(cls)
return PopularityComponentMock(cls)
# This class should be moved to the corresponding tests
@testcomponent
class PopularityComponentMock(PopularityComponent):
community = Mock()
We have the following folder structure: https://github.com/Tribler/tribler/tree/main/src/tribler-core/tribler_core
Components and modules should be merged into one single folder (as new "components" is old "modules").
There are no comments for the new complex logic (base.py
). We should add comments to make work with components easier, not harder.
An example:
If everybody agrees we need refactor, then sure. Otherwise I propose we relentlessly focus on users growth through Tribler improvements and accept the buildup of technical depth the remainder of the year.
buildup of technical depth the remainder of the year.
@synctext The buildup of technical debt you mean? I feel we have enough technical depth in our design now :wink:
@synctext I agree with your focus on features and improvements that can attract new users to Tribler. In the upcoming years, we can add many new exciting features to Tribler.
Components have one clear goal from the developer's perspective - allowing developers to add new features faster. For example, a new Tagging system definitely looks like a component to me. We need to discuss tomorrow does the current implementation satisfy this goal or it needs some changes.
Components architecture is intended to be a backbone of Tribler, and we need to be sure that the backbone is good enough to not collapse under the weight of new features. For that reason, I think the topics that @drew2a outlined are very good ones.
Having a working component architecture that all developers agree with can untie developer's hands and allow them to work on new features with improved speed. I believe that at this moment we already have a code that can be modified easily without spending a long additional time on it, so after the upcoming discussion, it should be easy to take into account our needs if they are not covered by the current approach.
sorry, I've been doing this for 16 years in Tribler, working on a generic framework to accelerate development time has been tried many times and consistently failed. :fearful:
Lesson from Dispersy, lesson from Libswift: never make a framework until you find yourself repeating the same thing 3 times. With tagging we're altering the core storage of metadata. It might evolve into a single unique piece of code which stores content with a trust-level. That will surely break all your assumptions. I'm hesitant to make anything "backbone" changes to Tribler. IPv8 communities are not broken, so our backbone does not need fixing.
At the Tribler team we have 4 scientific developers and 5 researchers. Everybody is trained to think independently as a system architect. So we have 10 system architects basically, me included. We have a systematic bias towards making too many architectural changes; striving for godly perfection. That is a problem to be aware of. The opposite may also happen. Similar projects like IPFS have no system architects and struggle {e.g. failed} with finding a good system architecture that will scale. Their team composition seems to be too narrow focused on individuals with their own task, losing track of cardinal global issues. For instance, as somebody smart said: IPFS/Filecoin is using a centralised business model for a decentralised system. :exploding_head:
I'm excited about the prospect of an offline all-dev-team meeting for discussing components. I'm sure that with the collective discussion, we can make the components architecture much better.
The current version of the components architecture has not emerged from an empty initial state. It was an incremental refactoring of the previous approach that you can see here.
First, I want to describe the component architecture that we have right now. The current implementation of components is trying to achieve the following goals:
Let's see how the current components implementation achieves that.
Now I can return to @drew2a notes about the current realization of components:
For each of the components, there are two types of objects:
- Implementation
- Interface
My main notes for interfaces are:
- Interfaces are unnecessary here (we can remove them)
Speaking about component objects, it is useful to separate the interface and the implementation of a component for the following reasons:
Speaking about component modules, you are correct that we can put an interface and the main implementation of the same component into the same module. But having different modules for interface and implementation is helpful for two reasons:
- Interfaces are not what they seem (technically, they looks more like Facades (https://en.wikipedia.org/wiki/Facade_pattern))
As I already wrote above, I disagree with this. In the current implementation, interfaces describe component fields in a strongly typed way. Inside your component, you can write (await self.use(LibtorrentComponent)).download_manager
, and PyCharm will correctly identify that the result's type is a DownloadManager
instance.
Let me compare the current way how components work with the previous iteration of the component architecture.
On the previous iteration, components indeed do not have interfaces. Each component had a single value which was provided by that component:
class TunnelsComponent(Component):
role = TUNNELS_COMMUNITY
...
async def run(self, mediator):
await super().run(mediator)
config = mediator.config
ipv8 = await self.use(mediator, IPV8_SERVICE)
bandwidth_community = await self.use(mediator, BANDWIDTH_ACCOUNTING_COMMUNITY)
peer = await self.use(mediator, MY_PEER)
dht_community = await self.use(mediator, DHT_DISCOVERY_COMMUNITY)
download_manager = await self.use(mediator, DOWNLOAD_MANAGER)
bootstrapper = await self.use(mediator, IPV8_BOOTSTRAPPER)
rest_manager = await self.use(mediator, REST_MANAGER)
In my opinion, this approach had the following drawbacks:
ipv8
or peer
here.IPV8_SERVICE
, MY_PEER
, and DHT_DISCOVERY_COMMUNITY
to pass three related values to TunnelsComponent.With component interfaces, we now have typed values, and a single component can hold more than one value. Now the same code looks like this:
class TunnelsComponentImp(TunnelsComponent):
async def run(self):
await self.use(ReporterComponent, required=False)
config = self.session.config
ipv8_component = await self.use(Ipv8Component)
ipv8 = ipv8_component.ipv8
peer = ipv8_component.peer
dht_discovery_community = ipv8_component.dht_discovery_community
bandwidth_component = await self.use(BandwidthAccountingComponent, required=False)
bandwidth_community = bandwidth_component.community if bandwidth_component.enabled else None
download_component = await self.use(LibtorrentComponent, required=False)
download_manager = download_component.download_manager if download_component.enabled else None
rest_component = await self.use(RESTComponent, required=False)
rest_manager = rest_component.rest_manager if rest_component.enabled else None
It does not look more concise because the code now takes into account that some optional components can be disabled in the Tribler configuration. But you can see the following differences:
Ipv8Component
can now provide multiple values: ipv8
, peer
and dht_discovery_community
.ipv8
or peer
is.
- A part of the interface's implementation has to be moved to the tests (see comments in the example below)
As I wrote above, in my opinion, this is confusion caused by an unfortunate naming. FoobarComponentMock
class is not intended to be used in tests exclusively. Its main purpose is to be used as a dummy replacement for the component when it is disabled in Tribler configuration. I think it is better to rename such classes to something like DummyFoobarComponent
.
We have the following folder structure: https://github.com/Tribler/tribler/tree/main/src/tribler-core/tribler_core
- components
- config
- modules
- restapi
- tests
- upgrade
- utilities
Components and modules should be merged into one single folder (as new "components" is old "modules").
Eventually, we should probably merge components and modules into a single folder. But right now, we don't have a one-to-one mapping between components and files in the modules
folder.
In previous iteration of components architecture, components reside in the modules directory. The directory structure looked like this (a subset of files and subdirectories):
modules
bandwidth_accounting
bandwidth_endpoint.py
community.py
component.py
...
category_filter
category.py
... (no component.py here)
exception_handler
component.py
exception_handler.py
...
ipv8
component.py
libtorrent
download.py
download_manager.py
... (no component.py here)
metadata_store
community
component.py
gigachannel_community.py
...
manager
component.py
gigachannel_manager.py
restapi
channels_endpoint.py
metadata_endpoint.py
... (no component.py here)
component.py
config.py
...
(...other subdirectories, some of them with components, others without)
bootstrap.py
component.py (base component class)
dht_health_manager.py
...
Was this directory layout more convenient as compared to having all components in a dedicated directory? To me, it wasn't, for the following reasons:
metadata_store/component.py
, metadata_store/community/component.py
, metadata_store/manager/component.py
, etc. With this layout, it is easy to miss a component hidden in some subfolder of another component.Having component implementations in a separate folder solves these two problems:
components
implementations
bandwith_accounting.py
gigachannel.py
gigachannel_manager.py
ipv8.py
libtorrent.py
(... and so on)
But in return, you need to have one more separate directory.
Each layout has some benefits and drawbacks. So, choosing the directory layout is a trade-off. We need to discuss it and choose a less annoying layout that has the least number of drawbacks. Then we can switch to the most desired layout quickly, with a simple IDE-supported refactoring.
There are no comments for the new complex logic (base.py).
Agree with that. I need to add comments and probably some internal documentation. Probably descriptions from the current thread can be used as a start for it.
In conclusion, I think that the current implementation of components has its warts. I usually don't like to have a big number of files and directories, as well as boilerplate code. I hope we can improve the current architecture after the discussion. But we need to have a common understanding of component architecture goals, possible trade-offs, and viable alternatives. Hopefully, with the forthcoming meeting, we can achieve this.
we have 10 system architects basically
And that's why no one cared about Tribler architecture all these years, right?
Their team composition seems to be too narrow focused on individuals with their own task, losing track of cardinal global issues.
I would argue that instead, this is exactly what was happening to our team all these years. PhDs and students don't care about the overall code quality and architecture. Their task is to get the job done ASAP and defend their thesis. Hence the (lack) of architecture. Also, our general scope was too broad.
never make a framework until you find yourself repeating the same thing 3 times.
The components refactoring is about not repeating the same thing 18 times over, which is:
In proper languages, such a C++, this kind of stuff is handled at the language level (e.g. constructors+destructors). Unfortunately, we have to invent our own :bike: in this case.
The components refactoring is about not repeating the same thing 18 times over [...] wait for pre-requisite component
Lets first slowly incrementally become feature complete, grow users and then do global changes. Are we fighting against our architecture to such an extend that it is slowing us down?
We learned for the mega pull request this summer that invasive architectural changes break a lot of our tooling (Gumby, app tester) and freeze all feature development for several months. Gumby is not even repaired and we're discussion the next big one? I'm opposed because its not broken. Module bootstrap frameworks may have operating system level complexity (systemd) and you easily fall into the trap of micro-services. However, if Tribler seniors @devos50 and @qstokkink agree that this is a good idea, then have fun!
(Haven’t done a full review of the components code)
My overall opinion is simple: if it ain’t broke, don’t fix it.
I highly appreciate the effort that has been put in creating these components, and I think it’s the most exciting part of #6206. Although there might be a few parts I might disagree with on an implementation level, it is good to see that we make components explicit and more flexible. At the same time, my (controversial) opinion is that the old way of working with components did the job, while acknowledging that it was far from perfect (I argued about this when discussing #6206). In summary, I believe the additional benefits of yet another design iteration on components would be low and I'm not in favour of one. Feel free to prove me wrong on this.
Having a working component architecture that all developers agree with can untie developer's hands and allow them to work on new features with improved speed.
With respect to components, development time is only saved when creating new components/understanding existing ones, not necessarily when working on a particular component. Since most of the development time concentrates on improving existing components/fixing bugs, the saved development time seems to be marginal. Explicit components do speed up the process of understanding the Tribler architecture and inter-component relations though.
it is good to see that we make components explicit and more flexible.
My fear is another mega pull request for improving component architecture. Lets set a clear rule today (can obviously be overruled by agreement of all Tribler developers): no more mega pull request this year. None.
To add confusing nuance. Lets see: if ? @drew2a ? can create pull requests of small size and its merely 2-3 days of effort; then I'm very much for it. So: minimal viable beauty improvement. It that realistic?
Based on the dev meeting (participants: @kozlovsky, @ichorid, @xoriole, @devos50, @drew2a) we decided that
invasive architectural changes ... freeze all feature development for several months.
This is simply not true. The only reason why feature development was frozen is because of developers taking a summer vacation.
Are we fighting against our architecture to such an extend that it is slowing us down?
No, because everyone is smart enough not to touch the smelly parts. The result is people tend to take sub-optimal architectural choices, increase technical debt, and not reusing the code produced by others. Egbert is gone now, thank :godmode: we already refactored the download wrapper last year. Otherwise, no one would be able to understand what to do if something breaks.
I've finished my part. All modules now merged with components:
@kozlovsky the remaining part is the documentation for component-session logic.
Transition to the components has been done. For more than a year we use them and now it is clear that they are good enough. The issue can be closed.
We have scheduled a meeting to discuss the implementation of the components. You can add your notes to this ticket.