Embedded Software Development Engineer to talk about software architecture design - know almost

write an essay

Embedded Software Development Engineer to talk about software architecture design

iMage

iMage

No longer feel terrible dreams

40 people agree with this article

Embedded Software Development Engineer to talk about software architecture design

Note: Here Embedded especially based on the Linux platform, SCM and other rtos beyond the scope


 

  • I engaged in embedded software development have six or seven years, bsp, drivers, application software, Android Hall, Framework and others have covered. In addition to the usual attention to the development of embedded industry, but also how much technology for Web, back-end server, distributed, such as the direction of some concern.
  • Recent initiation of the idea of a change in direction of the industry, want to do related to the development of back-end server, because the previous work and no real demand in this area, but their usual attention to learn some knowledge, such as: NIO, epoll, ngnix, zeromq , libevent, libuv, high concurrency, distributed, the Redis , the Python , Tornado, Django, heteroaryl covered comparison, a fur understand, not fine. Surprisingly often despised the Internet industry, interview opportunities are few.
  • At this point I think in the end what the problem is it, do not be so embedded origin has to be met it? At first, embedded, driver development, but the rush of the industry (a bit exaggerated, but 8, 9 years ago, but listening to the embedded likened the Java Web regressed to some oh)

The problem is always a reason, I say under my own understanding:

Embedded really tall on whether the Embedded Software Architect Why not?


 

  • Open the pull hook and other job sites, search architecture division, there will be a variety of systems architect, web architect, architect background server and so on, but alone it is difficult to see the embedded software architect. Embedded software architectures do not need, do not need to drive it architecture? The answer is of course necessary, but why no position in this regard?

My view: the current domestic embedded development is divided into the bottom of embedded development and embedded application development, embedded development in general is called the bottom-driven development, or bsp development, sometimes there are called linux kernel development, listening to all the names feeling on very big.

Why such a big name on the architect did not do: linux kernel architect is linus linux kernel development such as a public defenders, because of their own linux kernel or operating system is a common platform to address common problems, linux large open session cattle have developed a good architecture rules, leaving not many places to play, most of the work on it only needs to be filled in accordance with the rules of the framework, but also to present the majority of the company's business needs, just doing a peripheral device integration, porting embedded platform, build cutting, business requirements will not exceed the range of functions provided by the kernel inside. Resulting in no new architectures require developers to design, implement. Bsp that embedded developers are doing: In addition to commissioning a wide variety of peripherals, hardware for backside is some bug stability of the solution (for the specific job here is not described in detail, will only increase the number of debug peripheral experience, increase the breadth, depth is not to improve the contribution, not only by debugging - "will debug -" Start fast this line of development, and the solution is indeed require some stability problems accumulate experience)

The embedded application development, general business logic is relatively simple, a lot of people are ignored, so recruiters will feel no need to find an architect level.

At this point feel embedded industry really do not need an architect, was also despised the Internet industry no fuss.


 

  • But it is like this it? For the development of embedded underlying ability to kernel, driven architecture proposed architecture layer optimization, the domestic developers should not be much, so for most ordinary people, or do not "delusional" do architect of the Linux kernel (of course I I believe there are people in there must be the ability of Daniel), find and solve some bug, to fly some more.

Then for the development of embedded application layer, we really do not need it architecture?


 

  • In order to have an embedded device application software architecture design and optimization under about their actual experience: I once took over a project, the project uses multithreaded single process model, the project includes several modules to a, b, c , d, e representatives. The business logic of the project decided these modules have a lot of relevance. For example: The original design of a module is a state monitoring module, it will call b based on the monitored state, c module interface some of the features (benefits of multi-threading is a direct call is easy, so developers are mostly so dry, simple rude), but needs are always changing, adding a module f, f module also needs a module monitors the state of a process, according to the previous routine, this function is completed in two steps: 1, offers an interface module f, 2 , a call to the interface module. So far the new demand has been "perfect" to solve.
  • The aforementioned needs are always changing, new demand again, customers for custom needs, you need to add another g module, a module monitors the state of the same treatment, but does not require the need for customization just joined the f module, this time the most simple and crude way is to define a macro to distinguish between the need for customization and general demand before, build two versions of the program. This approach may seem simple, but gradually increased later if demand customization, maintenance of so many customized version of the program is a nightmare, code management and versatility will be a big problem, but the code is filled with differentiation for different macro definition processing, # ifdef xxx; do_something; #endif good practice to join the dynamic monitoring device model versions, dynamic supports all custom needs with a build version of the program, thus reducing the maintenance of different build procedures. But this approach only addresses the version build program maintenance work, does not solve the problem macro definition differentiated treatment, but the macro before the judge will, to a dynamic device to determine the version number, if these judgments differentiated only in one place carried out, it will not cause a big complicated problem, but obviously this is not good guarantee, there may be differences of these processes will spread to every corner of the entire project, this project will become a nightmare to maintain them.
  • The software does not require any advanced ideas, most people will think of the difference of the partially extracted out of place in a unified centralized management, changes to the differentiated only focus on the unified management of this place. A common practice is to use the callback set the hook, and then customize the difference in the callback in demand, do differentiated configuration process callback, which corresponds to the above example, it is to add a hook in a module, then at system initialization apparatus according to the version different number, differentiated custom callback handler, we also need to deal with these custom callback function in the same place, otherwise still scattered in various corners does not make sense (former approach is not to place the hooks of these differences can not be configured put together), this treatment brings another benefit is that we change the functional requirements and will not affect the processing of a module, that is, we add functionality without modifying the code a module of the (previous ways to modify a call flow module), so that it realizes the separation of a module.
  • The second point of the architecture program (actually mention the architecture) compared to the first program has been a lot of upgrading, so that at least some developers a little easier for other custom requirements, the need for developers to modify callback processing, attention differentiated part of it.

Software is the need to constantly evolve, the second option is the best solution right, of course not, there is room for optimization it?

The following Xianpao a problem, talk about the advantages and disadvantages / multi-process model of multi-threaded, multi-process mainly about the advantages of:

Textbook explanation is not mentioned, my first big project is respected multi-process model, irrespective of performance, for two main reasons:


 

  • Decoupling module: many developers, maintenance and development of multi-threaded model project should have how many there will be the following issues: cross-direct calls between modules, if you do not believe, well, you must be a sub-module project right now random delete a module, see if I can build through it (only need to build not need to run) under the build, I believe we will come across a function call in most cases, a situation of global variables can not be found, this note your strong coupling between modules exist. Because each multithreaded natural advantage, the address space visible, leading to a direct call is very easy, a lot of inexperienced engineer, it is easy to write simple and crude interface direct call, if you encounter a static interface function for easy map We will remove the static, take over direct use. So that the entire project with the function continued to add more and more crossover between modules, the higher the coupling.

The reason I respected reason is that multi-process, multi-process physically isolated from this "convenience" of communication, resulting in time want to implement a module interaction will think more about this interaction is necessary, and if so necessary, it will consider whether further simple interface definition (because inter-process communication will be relatively trouble some, developers will be able to reduce interaction in line with a clear idea of ​​the interface to carefully consider the definition of interfaces, protocols, or the toss of their own a), it is like life, if you have been so smooth, people may not think too much, think too much, but if some bumpy road, will have another perception of it.

So my idea is to model multi-process will force you to think more thought design process, reduce the physical coupling module .

  • Abstract generic components, separate business logic functions and common functions: When modifying a multi-threaded multi-process model of the process model, often find some interface code repeat occurs in the plurality of process modules, the interface function is because before a process space, everyone can be called directly, such as the interface module a is a, b invoked, module a, b separated after two separate processes, the interface a need a, b, respectively, to achieve a self-explanatory, duplicate code in software engineering, this is taboo, must be eliminated. Also very simple, these interfaces separation process is called multiple modules made lib, for other modules to call when you have finished this part of the work, what you find is not stripped of the interface can be used as general purpose of the project the presence of the assembly, the perfect case, the code is common in the lib base assembly, each module is an independent service processing module.
  • Convenient location problem: Multithreaded model when another thread exits abnormally, it will cause the entire process to exit, of course, through a number of crash information, you can locate the thread is dead, but if the thread module is composed of multiple teams, maintenance personnel, when after the collapse of the whole process out, how to judge resolved by that group would be a big problem, but sometimes there is the phenomenon of hanging on a thread, but in fact is another (coupling scourge) module caused by a thread encountered this case, the wrangling between the teams inevitable, prevarication. (Confident engineers think my code is not a problem)

And if the multi-process model, well, your service process hung up, find your own reasons for it, nothing to debate about the.

  • Easy performance testing : resource consumption multithreaded kinds single thread is not very good to see (at least some of the embedded system is not perfect command), when the whole process of resource consumption is high, the problem of how to determine the positioning of the module threads, like 3 difficult choices, and if it is multi-process model, who make up a lot of resources in the process, will come to check under the bar, in fact, this was a question of granularity, the same system is divided into multiple processes, the complexity of a single process lower than only a certain process complexity and more complexity reduction, find it easier to locate all kinds of problems.
  • Distributed Deployment: Internet industry has always emphasized distributed, cloud ah what the embedded industry to force a bitter, seemingly do not need any distributed, in fact, also, in most cases, the embedded single-chip, independent run, distributed encountered very little. But if in case you day in one device, the chip would have been a complete functional dispersed into two chips to handle it, it is easy to expand multi-process more.

This is just a special case, in fact, it is a distributed embedded device industry, but a beginning has been the separation, rather than from centralized to distributed route developed.

  • To facilitate the company's Code Privilege Isolation: Actually, I despise this practice, the company has to trust their own employees, but in view of good faith in China already. . . . , Do the isolation is understandable. Multi-threading model, if the removal of a module mentioned earlier, you probably can not build, then put all the code is exposed to all the engineers do, obviously not, so each module can only be provided in the form of libraries, but I think the generic function interface organized into a common repository is normal practice, if the business-related modules and also provided as a library, a bit. . . .

At this point add in all of these advantages, in fact, not very critical point, do not allow multiple processes have the absolute overwhelming superiority multi-threaded model, but from a personal point of view that, multi-process model is more forced engineers to solve some of the thinking problem. (These problems experienced engineers will think no matter what model)

It says so much, consider this example before the project into a multi-process model, otherwise it is only on paper, and began the following:

Bear the brunt of the problem is this: choose multi-process communication, direct calls between multiple threads is not used, then how to choose the communication multi-process it?


 

  • ipc offers many ways under linux, not enumerated here, for non- large data transfer amount of control, communications messages, the better way is to use socket, the more the present embodiment using the unix socket machine (this approach has What are the benefits? when you need to make a single system distributed system, advantage is obvious)
  • But only the use of socket to realize the function of the previous example, the same problems exist: or the previous example, first explained the second option after the earlier we can no longer continue to optimize the use of multi-process model, the reason is simple, should not be We need to explain. . .
  • Simple approach that is based on a program, the call was changed to direct socket communication (communication protocol can define good), but the familiar socket development engineers are aware that communication must first start socket some preliminary work (mainly connected to two associated modules), the previous example would become like this, to a module and the module b, c to establish a connection, if the added f modules, but also a module to establish a connection, and f. In this case the heart draw a connection diagram as if we will find a piece of spider web woven, intricate relationships between nodes, and a program and, we add a module and a related, it is necessary to modify a code module , and this situation more complex than multi-threaded model as well as more complicated. This approach is definitely a nightmare.

How to solve Well, I think a lot of people must think of ways using bus distribution. Learn android system development will think binder, understand openwrt would think ubus, Understanding Desktop think dbus, the Internet industry developers must know Redis Sub in the offer / pub module.

Above binder, ubus and other principle is very simple, is to create a message center, build a forward routing model, no direct interaction between all the other modules, instead of using the message center forwarding, routing, and how to determine the routing rules, a subscription / released observer pattern to define rules. (Embedded Development or C language developers often mistakenly think that design patterns are associated with an object-oriented language, object-oriented language is unique, although there are many large cattle and the popularity of this area, but given some of the developer's information relatively isolated channels, leading to this idea is still very popular)

Based on this model, our example above demand is a good solution, add a message center module, all modules need to communicate only with the message center module is connected, and then subscribe to events of interest, when an event occurs, only need to appropriate treatment on it.

Such above modules b, c subscription module a event, when the module is a detected to a certain event, release the event that the first incoming message center forwarding the message center to the module b, c, and for the new module added F, only needs to subscribe to the module, without the need to modify the code of a module, so that the extended function is very convenient.

While for customized development mentioned above is similarly streamlined, customized version if necessary to add modules g, this version will only need customized modules g as an independent process starts, then the event can be a subscription module, customized the difference between the version and the generic version of the module g is whether to start the process in order to achieve a goal of software engineering: adding functions as building blocks, just put a module into (start) or pull out (will not start) to change the function of a room or confined to a few modules, will not have any effect on the body frame.

Probably the above description of a gradual optimization of project requirements process, an example appears to be based on an embedded project, but seemingly equally applicable to software engineering.


 

  • Came the Internet industry: architects view the article in the major sites on this website to share technical architecture changes, usually the first mentioned, based on an application server functions previously split the business, more refined (such as electricity suppliers to sign in split registration, trading, commodities, sellers and other business services), then split out of the service deployed on multiple servers to provide concurrent. Are there some familiar, and spoke in front of a multi-threaded multi-process divided whether to have similar yet.

This split is also experiencing communication problems, this time a lot of messaging middleware emerged, such as Ali duboo, simple understanding of the principles of these middleware, nothing less than the subscription publication, RPC mechanisms, we can say much the same, but the difficulty It is to develop and improve the processing performance of the agreement.

Under the control of the Internet industry load balancing scheme, if the front-end load balancing, like the one message center.

Thus far, just to illustrate a problem, the software design is the same, based on the idea is the same, although the embedded industry's business logic is relatively simple, but in fact, after careful consideration, there will still be a lot of improvements on the structure, design.

But I feel sad that some embedded developers, given the simple business logic, using some not so good feeling approach can solve the problem, do not think about how to optimize and improve. For example, the above example of a program, if in little demand customization, maintenance is also no big problem, even more customization needs, and then recruit some junior programmers can maintain over a person responsible for a set of code the project company is not absent.

Also embedded industry and Internet industry should not exist a not insurmountable walls, we should be concerned about is the common software engineering ideas.

Edited on 2017-07-18

Embedded Development

Embedded Life

process

Agree 405 reviews

share it

Collect

<From: https://zhuanlan.zhihu.com/p/27958152?utm_source=wechat_session&utm_medium=social&utm_oi=27548712960000&from=singlemessage&isappinstalled=0&wechatShare=1&s_r=0>


Guess you like

Origin www.cnblogs.com/lizhensheng/p/11117388.html
Recommended