- 浏览: 982425 次
- 性别:
- 来自: 广州
最新评论
-
qingchuwudi:
有用,非常感谢!
erlang进程的优先级 -
zfjdiamond:
你好 这条命令 在那里输入??
你们有yum 我有LuaRocks -
simsunny22:
这个是在linux下运行的吧,在window下怎么运行escr ...
escript的高级特性 -
mozhenghua:
http://www.erlang.org/doc/apps/ ...
mnesia 分布协调的几个细节 -
fxltsbl:
A new record of 108000 HTTP req ...
Haproxy 1.4-dev2: barrier of 100k HTTP req/s crossed
Architecture of the Erlang odbc application
(对于我们编写c接口很大的借鉴意义,极大的提高了系统的稳定性,数据通信用tcp socket而不是pipe 提高通讯速度,port机制为了扑捉c程序的非正常退出, controlling进程用于提供timeout通知,数据格式直接用term, c程序直接用ei构造和解码格式 一切看起来都简单 设计的太精妙了)
4 Error handling
4.1 Strategy
On a conceptual level starting a database connection using the Erlang ODBC API is a basic client server application. The client process uses the API to start and communicate with the server process that manages the connection. The strategy of the Erlang ODBC application is that programming faults in the application itself will cause the connection process to terminate abnormally.(When a process terminates abnormally its supervisor will log relevant error reports.) Calls to API functions during or after termination of the connection process, will return {error, connection_closed}. Contextual errors on the other hand will not terminate the connection it will only return {error, Reason} to the client, where Reason may be any erlang term.
4.1.1 Clients
The connection is associated with the process that created it and can only be accessed through it. The reason for this is to preserve the semantics of result sets and transactions when select_count/[2,3] is called or auto_commit is turned off. Attempts to use the connection from another process will fail. This will not effect the connection. On the other hand, if the client process dies the connection will be terminated.
4.1.2 Timeouts
All request made by the client to the connection are synchronous. If the timeout is used and expires the client process will exit with reason timeout. Proably the right thing to do is let the client die and perhaps be restarted by its supervisor. But if the client chooses to catch this timeout, it is a good idea to wait a little while before trying again. If there are too many consecutive timeouts that are caught the connection process will conclude that there is something radically wrong and terminate the connection.
4.1.3 Gaurds
All API-functions are guarded and if you pass an argument of the wrong type a runtime error will occur. All input parameters to internal functions are trusted to be correct. It is a good programming practise to only distrust input from truly external sources. You are not supposed to catch these errors, it will only make the code very messy and much more complex, which introduces more bugs and in the worst case also covers up the actual faults. Put your effort on testing instead, you should trust your own input.
4.2 The whole picture
As the Erlang ODBC application relies on third party products and communicates with a database that proably runs on an other computer in the network there are plenty of things that might go wrong. To fully understand the things that might happen it facilitate to know the design of the Erlang ODBC application, hence here follows a short description of the current design.
Note
Please note that design is something, that not necessarily will, but might change in future releases. While the semantics of the API will not change as it is independent of the implementation.
odbc_app_arc
Architecture of the Erlang odbc application
When you do application:start(odbc) the only thing that happens is that a supervisor process is started. For each call to the API function connect/2 a process is spawned and added as a child to the Erlang ODBC supervisor. The supervisors only tasks are to provide error-log reports, if a child process should die abnormally, and the possibility to do a code change. Only the client process has the knowledge to decide if this connection managing process should be restarted.
The erlang connection process spawned by connect/2, will open a port to a c-process that handles the communication with the database through Microsoft's ODBC API. The erlang port will be kept open for exit signal propagation, if something goes wrong in the c-process and it exits we want know as mush as possible about the reason. The main communication with the c-process is done through sockets. The C-process consists of two threads, the supervisor thread and the database handler thread. The supervisor thread checks for shutdown messages on the supervisor socket and the database handler thread receives requests and sends answers on the database socket. If the database thread seems to hang on some database call, the erlang control process will send a shutdown message on the supervisor socket, in this case the c-process will exit. If the c-process crashes/exits it will bring the erlang-process down too and vice versa i.e. the connection is terminated.
Note
The function connect/2 will start the odbc application if that is not already done. In this case a supervisor information log will be produced stating that the odbc application was started as a temporary application. It is really the responsibility of the application that uses the API too make sure it is started in the desired way.
4.2.1 Error types
The types of errors that may occur can be divide into the following categories.
* Configuration problems - Everything from that the database was not set up right to that the c-program that should be run through the erlang port was not compiled for your platform.
* Errors discovered by the ODBC driver - If calls to the ODBC-driver fails due to circumstances that can not be controlled by the Erlang ODBC application programmer, an error string will be dug up from the driver. This string will be the Reason in the {error, Reason} return value. How good this error message is will of course be driver dependent. Examples of such circumstances are trying to insert the same key twice, invalid SQL-queries and that the database has gone off line.
* Connection termination - If a connection is terminated in an abnormal way, or if you try to use a connection that you have already terminated in a normal way by calling disconnect/1, the return value will be{error, connection_closed}. A connection could end abnormally because of an programming error in the Erlang ODBC application, but also if the ODBC driver crashes.
* Contextual errors - If API functions are used in the wrong context, the Reason in the error tuple will be a descriptive atom. For instance if you try to call the function last/[1,2] without first calling select_count/[2,3] to associate a result set with the connection. If the ODBC-driver does not support some functions, or if you disabled some functionality for a connection and then try to use it.
附图
(对于我们编写c接口很大的借鉴意义,极大的提高了系统的稳定性,数据通信用tcp socket而不是pipe 提高通讯速度,port机制为了扑捉c程序的非正常退出, controlling进程用于提供timeout通知,数据格式直接用term, c程序直接用ei构造和解码格式 一切看起来都简单 设计的太精妙了)
4 Error handling
4.1 Strategy
On a conceptual level starting a database connection using the Erlang ODBC API is a basic client server application. The client process uses the API to start and communicate with the server process that manages the connection. The strategy of the Erlang ODBC application is that programming faults in the application itself will cause the connection process to terminate abnormally.(When a process terminates abnormally its supervisor will log relevant error reports.) Calls to API functions during or after termination of the connection process, will return {error, connection_closed}. Contextual errors on the other hand will not terminate the connection it will only return {error, Reason} to the client, where Reason may be any erlang term.
4.1.1 Clients
The connection is associated with the process that created it and can only be accessed through it. The reason for this is to preserve the semantics of result sets and transactions when select_count/[2,3] is called or auto_commit is turned off. Attempts to use the connection from another process will fail. This will not effect the connection. On the other hand, if the client process dies the connection will be terminated.
4.1.2 Timeouts
All request made by the client to the connection are synchronous. If the timeout is used and expires the client process will exit with reason timeout. Proably the right thing to do is let the client die and perhaps be restarted by its supervisor. But if the client chooses to catch this timeout, it is a good idea to wait a little while before trying again. If there are too many consecutive timeouts that are caught the connection process will conclude that there is something radically wrong and terminate the connection.
4.1.3 Gaurds
All API-functions are guarded and if you pass an argument of the wrong type a runtime error will occur. All input parameters to internal functions are trusted to be correct. It is a good programming practise to only distrust input from truly external sources. You are not supposed to catch these errors, it will only make the code very messy and much more complex, which introduces more bugs and in the worst case also covers up the actual faults. Put your effort on testing instead, you should trust your own input.
4.2 The whole picture
As the Erlang ODBC application relies on third party products and communicates with a database that proably runs on an other computer in the network there are plenty of things that might go wrong. To fully understand the things that might happen it facilitate to know the design of the Erlang ODBC application, hence here follows a short description of the current design.
Note
Please note that design is something, that not necessarily will, but might change in future releases. While the semantics of the API will not change as it is independent of the implementation.
odbc_app_arc
Architecture of the Erlang odbc application
When you do application:start(odbc) the only thing that happens is that a supervisor process is started. For each call to the API function connect/2 a process is spawned and added as a child to the Erlang ODBC supervisor. The supervisors only tasks are to provide error-log reports, if a child process should die abnormally, and the possibility to do a code change. Only the client process has the knowledge to decide if this connection managing process should be restarted.
The erlang connection process spawned by connect/2, will open a port to a c-process that handles the communication with the database through Microsoft's ODBC API. The erlang port will be kept open for exit signal propagation, if something goes wrong in the c-process and it exits we want know as mush as possible about the reason. The main communication with the c-process is done through sockets. The C-process consists of two threads, the supervisor thread and the database handler thread. The supervisor thread checks for shutdown messages on the supervisor socket and the database handler thread receives requests and sends answers on the database socket. If the database thread seems to hang on some database call, the erlang control process will send a shutdown message on the supervisor socket, in this case the c-process will exit. If the c-process crashes/exits it will bring the erlang-process down too and vice versa i.e. the connection is terminated.
Note
The function connect/2 will start the odbc application if that is not already done. In this case a supervisor information log will be produced stating that the odbc application was started as a temporary application. It is really the responsibility of the application that uses the API too make sure it is started in the desired way.
4.2.1 Error types
The types of errors that may occur can be divide into the following categories.
* Configuration problems - Everything from that the database was not set up right to that the c-program that should be run through the erlang port was not compiled for your platform.
* Errors discovered by the ODBC driver - If calls to the ODBC-driver fails due to circumstances that can not be controlled by the Erlang ODBC application programmer, an error string will be dug up from the driver. This string will be the Reason in the {error, Reason} return value. How good this error message is will of course be driver dependent. Examples of such circumstances are trying to insert the same key twice, invalid SQL-queries and that the database has gone off line.
* Connection termination - If a connection is terminated in an abnormal way, or if you try to use a connection that you have already terminated in a normal way by calling disconnect/1, the return value will be{error, connection_closed}. A connection could end abnormally because of an programming error in the Erlang ODBC application, but also if the ODBC driver crashes.
* Contextual errors - If API functions are used in the wrong context, the Reason in the error tuple will be a descriptive atom. For instance if you try to call the function last/[1,2] without first calling select_count/[2,3] to associate a result set with the connection. If the ODBC-driver does not support some functions, or if you disabled some functionality for a connection and then try to use it.
附图
评论
3 楼
mryufeng
2009-03-17
DESCRIPTION: Erlang ODBC (Open Database Connectivity) application. An
erlang control process sends request to the c-process that queries the
database using the Microsoft ODBC API. The c-process is implemented
using two threads the supervisor thread and the database handler thread.
If the database thread should hang erlang can close the c-process down
by sendig a shutdown request to the supervisor thread.
Erlang will start this c-process as a port-program and send information
regarding inet-port nummbers through the erlang-port.
After that c-process will communicate via sockets with erlang. The
reason for this is that some odbc-drivers do unexpected things with
stdin/stdout messing up the erlang-port communication.
erlang control process sends request to the c-process that queries the
database using the Microsoft ODBC API. The c-process is implemented
using two threads the supervisor thread and the database handler thread.
If the database thread should hang erlang can close the c-process down
by sendig a shutdown request to the supervisor thread.
Erlang will start this c-process as a port-program and send information
regarding inet-port nummbers through the erlang-port.
After that c-process will communicate via sockets with erlang. The
reason for this is that some odbc-drivers do unexpected things with
stdin/stdout messing up the erlang-port communication.
2 楼
mryufeng
2009-03-16
这种程序在混合系统中相当普遍,写类似程序相当好的教材!
1 楼
mryufeng
2009-03-16
小程序 大思路
发表评论
-
OTP R14A今天发布了
2010-06-17 14:36 2677以下是这次发布的亮点,没有太大的性能改进, 主要是修理了很多B ... -
R14A实现了EEP31,添加了binary模块
2010-05-21 15:15 3030Erlang的binary数据结构非常强大,而且偏向底层,在作 ... -
如何查看节点的可用句柄数目和已用句柄数
2010-04-08 03:31 4814很多同学在使用erlang的过程中, 碰到了很奇怪的问题, 后 ... -
获取Erlang系统信息的代码片段
2010-04-06 21:49 3475从lib/megaco/src/tcp/megaco_tcp_ ... -
iolist跟list有什么区别?
2010-04-06 20:30 6529看到erlang-china.org上有个 ... -
erlang:send_after和erlang:start_timer的使用解释
2010-04-06 18:31 8386前段时间arksea 同学提出这个问题, 因为文档里面写的很不 ... -
Latest news from the Erlang/OTP team at Ericsson 2010
2010-04-05 19:23 2013参考Talk http://www.erlang-factor ... -
对try 异常 运行的疑问,为什么出现两种结果
2010-04-05 19:22 2842郎咸武<langxianzhe@163.com> ... -
Erlang ERTS Async基础设施
2010-03-19 00:03 2517其实Erts的Async做的很不错的, 相当的完备, 性能又高 ... -
CloudI 0.0.9 Released, A Cloud as an Interface
2010-03-09 22:32 2476基于Erlang的云平台 看了下代码 质量还是不错的 完成了不 ... -
Memory matters - even in Erlang (再次说明了了解内存如何工作的必要性)
2010-03-09 20:26 3439原文地址:http://www.lshift.net/blog ... -
Some simple examples of using Erlang’s XPath implementation
2010-03-08 23:30 2050原文地址 http://www.lshift.net/blog ... -
lcnt 环境搭建
2010-02-26 16:19 2614抄书:otp_doc_html_R13B04/lib/tool ... -
Erlang强大的代码重构工具 tidier
2010-02-25 16:22 2486Jan 29, 2010 We are very happy ... -
[Feb 24 2010] Erlang/OTP R13B04 has been released
2010-02-25 00:31 1387Erlang/OTP R13B04 has been rele ... -
R13B04 Installation
2010-01-28 10:28 1390R13B04后erlang的源码编译为了考虑移植性,就改变了编 ... -
Running tests
2010-01-19 14:51 1486R13B03以后 OTP的模块加入了大量的测试模块,这些模块都 ... -
R13B04在细化Binary heap
2010-01-14 15:11 1508从github otp的更新日志可以清楚的看到otp R13B ... -
R13B03 binary vheap有助减少binary内存压力
2009-11-29 16:07 1668R13B03 binary vheap有助减少binary内存 ... -
erl_nif 扩展erlang的另外一种方法
2009-11-26 01:02 3218我们知道扩展erl有2种方法, driver和port. 这2 ...
相关推荐
### Erlang与C语言程序接口详解 #### 一、引言 在软件开发领域,不同编程语言之间的交互是一项重要的技术。Erlang作为一种专为构建高并发、容错性强的应用程序而设计的语言,在与其他语言(如C语言)的集成方面具有...
9. **MVC架构**:尽管Erlang本身并不强制使用特定的设计模式,但Nitrogen框架鼓励采用Model-View-Controller(MVC)模式进行开发,帮助分离业务逻辑、视图呈现和数据处理。 10. **学习曲线**:对于熟悉Erlang的...
**Erlang MySQL 驱动接口详解** 在Erlang编程环境中,与MySQL数据库进行交互通常需要依赖特定的驱动接口。本文将深入探讨Erlang的MySQL驱动接口,包括其设计原理、使用方法和常见操作,以帮助开发者更好地理解和...
Port Driver 可能与其他 Erlang 外部接口技术,如 NIF(Native Implemented Function)或 ETS(Erlang Term Storage)进行了对比。 标签 "erlang post driver test" 强调了测试的焦点是关于 Erlang 的 Port Driver...
erlang安装包
Erlang支持编写外部接口程序(port drivers),它们可以用C语言等外部语言实现,以与外部世界通信。 #### 14. 系统监控和管理 Erlang的监控机制允许进程监控其它进程的状态,以便系统能够在进程失败时进行相应的...
这是第一卷。 在2008 CN Erlounge III的“Erlang应用程序接口”讲演的视频。PPT等其它资料在这里: http://blog.csdn.net/aimingoo/archive/2009/01/14/3777765.aspx 有关信息参见: ...
我在Erlounge III大会上的讲演PPT。 相关的视频在这里: http://groups.google.com/group/erlang-china/browse_thread/thread/2154c39503795edc
erlang-odbc-19.3.6.4-1.el7.x86_64.rpm
**Erlang编程:Introducing Erlang** Erlang是一种函数式编程语言,由爱立信在1986年开发,主要用于构建高可用性、容错性和并发性的分布式系统。"Introducing Erlang"是Simon St. Laurent撰写的一本入门级教程,...
**外部接口**:Erlang进程与外部世界的交互也依赖于消息传递,这保持了一致性,简化了系统的复杂性。 **Fail-fast原则**:Erlang倾向于快速暴露错误,以便开发者能尽早发现问题并修复。 **面向并发的编程**:...
Erlang的安装包分为32位和64位两种,这对应于不同的操作系统架构。32位版本适用于传统的32位操作系统,如Windows XP 32-bit或某些旧版Linux发行版。64位版本则用于64位操作系统,如Windows 10 64-bit、macOS以及...
7. **兼容性**:Erlang22可能会改进与其他软件和硬件平台的兼容性,包括新的操作系统版本和硬件架构。 要使用`otp_src_22.1`构建Erlang环境,开发者需要遵循以下步骤: 1. **解压源码**:首先,使用tar命令解压文件...
1、数据信息采用基于HTML5的大负载架构设计(Erlang)的长连接推送技术,高效且节省资源; 2、提供金融短讯、操作建议、经验秘籍等栏目功能; 3、应用运行时可设置是否待机功能,应用在后台运行时根据设置可关闭...
Erlang是一种高级编程语言,特别适用于并发、分布式和实时系统。它由Ericsson公司开发,主要用于构建高可用性、容错性和可扩展性的软实时系统。Erlang的25.0版本是该语言的一个更新,针对Windows操作系统进行了优化...
1、数据信息采用基于HTML5的大负载架构设计(Erlang)的长连接推送技术,高效且节省资源; 2、提供金融短讯、操作建议、经验秘籍等栏目功能; 3、应用运行时可设置是否待机功能,应用在后台运行时根据设置可关闭在线...
Erlang是一种面向并发的、函数式编程语言,由瑞典电信设备制造商Ericsson开发,主要用于构建高可用性、分布式和实时系统。版本24.3.4.4是Erlang的一个更新版本,包含了对先前版本的改进和修复。Erlang以其强大的错误...
通常,这样的库会提供接口函数,用于执行 SQL 查询、插入、更新和删除数据,以及处理连接和事务等操作。 以下是一些关键知识点: 1. **Erlang MySQL 驱动**:Erlang MySQL 驱动是连接 MySQL 数据库的关键组件,它...
在Erlang中,这种接口通常遵循JDBC或ODBC风格的API,尽管Erlang并不直接支持这些接口,而是有类似的设计模式。 对接过程主要包括以下步骤: 1. **安装驱动**:首先,你需要在Erlang环境中安装这个驱动库。这可能...