<< 二月 2011 | 首页 | 四月 2011 >>

如何解開 Android 手機的 Rom

解開 img 格式的檔案:

最常見的應該是 img 格式的檔案,

雖然都是 img 格式可是其實有分成兩種,

一種是 boot.img 和 recovery.img 的格式,

這兩個檔案用的是 android 自己定義的格式,

boot.img 和 recovery.img 的解壓縮可以參考下面這篇文章解開
http://android-dls.com/wiki/index.php?title=HOWTO:_Unpack%2C_Edit%2C_and_Re-Pack_Boot_Images

另外的 system.img / recovery.img 等分割區則是採用 yaffs2 格式,

我將解壓縮的工具上傳到下面的網址,

http://www.megaupload.com/?d=BLRZORM0 System/Userdata image unpack tool for windows

http://unyaffs.googlecode.com/files/unyaffs System/Userdata image unpack tool for linux

windows 使用時只要把 system.img 用滑鼠拖曳到 unpack.bat 圖示上面就會自動解壓縮了
(會展開在該目錄下所以會有點亂)

linux 則可以透過下列命令解開 xxx.img

#./unyaff system.img
另外 system.tar 則是可以用 winrar 或是 tar 直接開啟和 system.img 內容相同

system.img 備份
http://www.megaupload.com/?d=4Z9DBQ7Y A688 system.tar
http://www.megaupload.com/?d=58N1F0Y0 A688 system.img

解開 nb0 格式的檔案:
大陸那邊的首派 A60 這隻跟 A688 幾乎相同的手機
有放出 Rom 而且是單一檔案的格式(xxx.nb0),
可以透過 RUT 這個刷機程式刷成 A60 官方的系統,
(聽說有去掉了某些 Google 服務)
透過我下面的連結裡面的 nb0-utils.exe 這個程式可以
http://www.megaupload.com/?d=X1LAJDPN A688 Tools
可以把 nb0 解開成 img 的格式,
nb0-utils.exe unpack FXX-0380-0-0000-7003-A01.nb0 a60
nb0-utils.exe unpack <nb0 檔案名稱> <要解開到哪個資料夾(要先存在)>
在 a60 資料夾下面會看到很多 xxx.xml xxx.img 的檔案
要把檔案打包回去則是下
nb0-utils.exe pack a60.nb0 a60
A60 官方 Rom 下載
http://www.megaupload.com/?d=8WNQ8OLR
下面這幾個是我解開的大陸首派 A60 的 Rom 順便備份下
http://www.megaupload.com/?d=9S4P9CKH A60 boot.img
http://www.megaupload.com/?d=6PHNS9Y0 A60 ftm.img
http://www.megaupload.com/?d=0LWRSZVS A60 hidden.img
http://www.megaupload.com/?d=K4I092LU A60 recovery.img
http://www.megaupload.com/?d=VOH6JK3Q A60 splash.img
http://www.megaupload.com/?d=0IIJ0KQ5 A60 system.img

=================================

另外 A688 的開機畫面分成 splash 和 開機動畫兩部分,
splash 就是下面的 splash.img 開機第一眼看到的威寶商標畫面,
另外還有兩段由圖片組成的動畫放在 hidden.img 的
/hidden/data/Power-on animation/ 下面,
圖片大小為 320x480 全彩 png 可以拿相同格式的圖替換,
就算弄錯也只是沒開機畫面而已,
用 Root Expoler 就可以替換

 
标签 :

处理Java Out of Memory问题步骤

1. 收集与分析verbose gc 的错误讯息输出

* 将“verbosegc“参数加入命令提示列启动Server,这将会将GC 的活动信息显示在标准输出/输入,转到stdout/stderr 的档案中。执行应用程序直到问题再次产生。

* 确定在java out of memory 之前,JVM 做如下内容:

* Full GC run:

执行full GC 与所有soft/weak/phantomly reachable 的对象能被移除与这些空间能被回收,在下面网址可以找到更多不同等级对象消耗细项说明:

http://java.sun.com/developer/technicalArticles/ALT/RefObj

你能检查full GC out of memory 讯息之前做,接下来的一个讯息显示当GC 已经完成(讯息的格式是依照JVM 定义,检查JVM Help message 以了解讯息格式)

[memory ] 7.160: GC 131072K->130052K (131072K) in 1057.359 ms

下面是上面格式的说明(注意:相似格式将会被使用在遍及这份文件)

[memory ] <start>: GC <before>K-><after>K (<heap>K), <total> ms

[memory ] <start> - start time of collection (seconds since jvm start)

[memory ] <before> - memory used by objects before collection (KB)

[memory ] <after> - memory used by objects after collection (KB)

[memory ] <heap> - size of heap after collection (KB)

[memory ] <total> - total time of collection (milliseconds)

然而,这无法使用讯息推断soft/weak/phantomly reachable objects 被移除。假如GC 算法是generational 算法,你会看到verbose 输出像这样:

[memory ] 2.414: Nursery GC 31000K->20760K (75776K), 0.469 ms

上述是nursery GC(young GC)循环将会提升正在执行的objects

nursery(young space)old space。这个循环不是重要的分析,更详细项目有关generational 算法可以在JVM 的文件中找到;假如GC 的循环不是发生在java out of memory,这样就可能是JVM bug

* Full compaction:

保证JVM 做适当的紧密程度工作,内存没有碎裂,能防止large objects被配置而且引发一个java out of memory 错误。Java Objects 需要连续的记忆区块,假如没有空的内存区块,那么JVM 将无法配置一个large objects,它将无法符合任何一个空的区块。在这个情况下JVM 将会做full compaction,这样才会有更多连续内存区块能够符合容纳large objectsCompaction 工作包含移动objects(data)java heap memory 一个区堆到另一个与更新references 到这些objects 的指定的新的位置上。JVM 将不会重排所有objects,除非这是需要的。这是减少GC 循环的暂停时间。我们能否透过verbose gc 讯息检查出内存碎裂的java out of memory

假如我们看到输出像下列所示,即使仍有空的java heap out of memory 还是会发生,是因为内存碎裂的原因。

[memory ] 8.162: GC 73043K->72989K (131072K) in 12.938 ms

[memory ] 8.172: GC 72989K->72905K (131072K) in 12.000 ms

[memory ] 8.182: GC 72905K->72580K (131072K) in 13.509 ms

java.lang.OutOfMemoryError

以上的情况你能够看出max heap 是被设定128MB JVM 丢出out ofmemory 当物理内存使用只有72580KHeap 使用率只有55%。因此,即使当有45%free heap 的时候,在这个案例内存碎裂的影响仍会丢出out of

memory。这是JVM bug 或是限制。你必需联络原厂请求协助。

 

2. 假如JVM 运作是正常的

假如JVM 运作是正常的(的在上述所提及的动作),那么java out of memory可能是应用程序的问题。这个应用程序可能不断泄漏一些java memory,可能是会引发这个问题。或者是应用程序使用过多的objects 它需要更多的heapmemory,以下是可以在这个应用程序中做检查的:

* 应用程序的caching

假如应用程序在内存中caches java objects,那么我们将需要确定这个cache 是否一直在成长;可能需要在cache 中限制objects 的数量。我们能试着降低这个限制看看是否它会降低java heap 使用量。JAVA soft references softly reachable objects 一样使用data caching,当JVM 执行发生out of heap 时,是允许被移除。

* 执行过久的objects

假如在应用系统里有在Heap 中存在过久的objects,那么我们可以尽可能地试着降低存在的objects。例如:调校HTTP session timeout 将能帮助更快回收无效session objects

* Memory leaks

一个memory leak 的范例是在应用系统中使用database connectionpools。当使用connection poolsJDBC statement resultset objects必需确定最后有被关闭。这基于事实,这由于从pool 中的connection

objects 使用呼叫close(),将简单connection 传回到pool 以提供重新使用,若没有真正关闭connection 与关联到的statement/resultset

objects

* 增加java heap

我们也能试着增加java heap 假如可能的话看是否能解决问题。

 

3. 假如不是属于前两者的状况:

那们我们需要使用JVMPI(JVM Profiler Interface)基础profiler Jprobe OptimizeIt 去找出那些Objects 是占住java heapprofilers 也从这些对象正被建立的地方,在java code 里的细节地方上。这份数据不包括在每profiler 上的细节。profiler 文件可能提到有关如何设定与启动应用系统与profilers 通常,基于JVMPI

profilers 会有过多负担与大大降低应用系统的效能。因此,在上线环境里使用这些profilers 是不适当的。

 

For Native OOM Problem:

1. 收集下列信息

* –verbosegc output to monitor the java heap usage.

这将能帮助了解应用系统的java memory 需求。应用系统它可能会需要独立使用的实际java heap,在JVM 启动时预留最大的heap 设定(使用-Xmx 参数在java 命令提示列)与在其他用途是不允许预留内存。在这个Jrockit 的案例,使用-verbose 取代-verbosegc 如同在GC 信息中增加给codegen 信息。* 记录Process virtual memory size 从应用系统被启动时,开始在JVM执行到out of native memory;这将能帮助了解不管是process 真的达到操作系统的大小限制。在Windows 的案例,遵照下列程度监控virtual process size:在开始\执行,输入”perfmon”并且按OKPerformance 图形上方按下“+“按键选择下面项目:

性能对象: Process (不是预设的processor)

从清单选取计数器: Virtual Bytes

从清单选择例项: Select the JVM (java) instance

“新增”, 并且 “关闭”

Unix Linux 中对于PID 而言,virtual memory size 能够使用这个命令看到:– ps p <PID> -o vsz.

Linux 中每一个java thread 都会有单一个JVM instance process方式显示,假如我们选择一个root java process PID,这个root javaprocess 可以使用ps 命令加上-forest 参数能够被发现,例如:ps IU

<user> --forst 将会显示某一特定用户所有process ASCII 的树状结构显示,你还可以从这树状结构找到root java

 

2. 机器上可用的内存

假如机器RAM swap space 是不足,那么操作系统将无法提供更多的内存给process,那么也可能造成out of memory 的结果,确定同机器上的RAM

swap space 在硬盘空间的加总是足够执行所有的Process

3. Java heap 调校

假如java heap 的使用都在max heap 之内,那么可以考虑降低max heap的大小,以提供更多的native memory JVM 使用。这并不是一个解决方案,但是一个测试的变通方法。因为操作系统限定process 大小,我们需要在javaheap native heap 之间达到一个平衡。

 

4. JVM Native memory 使用量

在所有的classes 被加载JVM Native memory 使用量是将可预期会趋于平稳,并且方法已被呼叫(code 的产生已经结束)。应用系统通常发生在最初的几个小时,在那之后,JVM 可能在执行时加载classcode 的优化只需要很小的native memory

为了减少问题,试着取消执行时优化并且检查是否有何不同。* 在这个jrockit 案例,参数-Xnoopt 能够取消执行时优化。在SUNJVM,参数-Xint 将强制JVM执行在interpreted mode(nocode generation)。假如执行时native memory 使用量仍持续成长,那么问题就可能是在native

code 这边发生。

5. 应用程序中Third party native modules JNI code

检查不论你是使用Third party native module 像是database driver,这些native modules 可能也会配置native memory 并且漏洞可能就是这些modules。基于缩小问题,你能试着重建问题在不使用协助厂商的driver,例如:你能使用pure java drivers 取代native database drivers。检查你的应用系统是否使用JNI 的程序代码,这也可能造成native memory泄漏,并且你也可以尝试执行应用系统尽量不使用JNI 程序代码。

6. 假如照上述步骤仍无法找出native memory 问题

那么你就得向JVM 厂商取得能侦测native memory 配置的特别的版本并且更多有关JVM 上有关内存泄漏的讯息。

结论

系统开发时往往问题发生out of memory,或内存一直成长无法透过GC回到平均值时,这往往不知道该如何处理此问题所在,到底是应用系统问题,还是JDK 发生的问题,以上的这些是针对有关Memory leak 问题进行说明的了解,与问题排解原则加以说明,期望日后再碰到此问题能有所参考依据与检测的方式,以让此类问题能够不再发生。

 

标签 : ,

何謂Java heap, Native memory and Process Size

一般在3-tier 架构下的应用系统,最常的问题就是Out of Memory(内存),或Memory leak(内存泄)况,最后往往导致Application

Server失效与系统Crash,让管人员必需常常守候在Server 旁边,注意它关心它系统况与运作情形避免它Crash。而本专题报导则是针对此型问题

的发生,从JVM 其基本架构开始明,并采用问答与实的方式进行說明解释,并且提供检查的项目明,可藉由这些项目自我检测,以避免发生Memory

leak 有效掌握Resource
 
何谓Out of MemoryMemory leak
Out of Memory
定义
 
内存不論Java heap Native Memory 足以提供给组件使用。
 
Memory leak
定义
 
组件的内存使用不論Java heap Native Memory 中持续成长,
最后导致发生Out of memory 的情况。
 
何谓Java heap, Native memory and Process Size
Memory leak 问题的发生,首先先解几个JVM 的内存管重要的名称:
 
Java heap
这是JVM 配置Java objects 的内存,Java heap 内存大小是透过命行列中下的參數-Xmx 设定的。假如最大的heap size 没有定义,那么它的

大小限制将由JVM 视当时情况如机器的物理内存与剩下可用的内存决定。因此一般都建议要设定最大的Java heap 的值。
 
Native Memory
这是JVM 它内部运作的内存,Native Memory Heap 将是会被JVM使用,而它的大小取决于产生的程序代码、产生的threadGC

时用于保存javaobject 信息与产生或优化程序代码时的暂存空间假如它是Third party native module,它将可能使用Native Memory.如:native

JDBC driver 就是配置Native Memory
Native Memory
的最大值是会受限于任何一OS virtual process size 与已经被參數-Xmx 指定给Java Heap 的内存大小。如:假如应用系统能够

总共配置3GB,并且假如最大的Java Heap 大小为1G,那么Native Memory 最大值可能接近2GB
 
Process Size
Process Size
将会是Java HeapNative Memory 与被用于已加载执与函式库的内存的加总,在32 位的操作系统,一个处程序虚拟寻址空间能

够到4GB超过4GB,操作系统的核心将会预一部份给它自己使用(一般是1~2GB)。那么剩下的就是给应用系统。Windows:假设有4GB 的内存,预

设给应用系统使用最大2GB 与而另外的2GB

是给核心使用。仅管如此,在一些同版本的Windows,可以用/3GB參數切换这个比值,让应用系统可以得到3GB 的内存。详细可Microsoft网站,

址址:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/ddtools/hh/ddtools/bootini_1fcj.asp
Red Hat AS 2.1
:应用系统可以使用到最大内存大小为3GB其他的操作系统,请考该操作系统文件做设定。
 
Process
寻址空间与物理内存的
每一个Process 都拥有自己的寻址空间,在32 位操作系统,这个寻址空间是介于0 4GB 之间。这是机器上独RAM Swap Space,机器上全部

的物理内存是同一台机器上的RAM Swap Space 的加总,所有执中的Process 分享这个物理内存。Process 的内存寻址是虚拟的。操作系统

核心对应这虚拟地址到实体地址。实体地址指到物理内存中的某一个位置。在一台机器上任何特定时间所有被正在执Process 的虚拟内存,其

加总能超出在同一台机器上全部物理内存大小。
 
为何会Out of Memory 问题发生?在这个况发生
JVM
会做么处置?
 
Out of Memory in java heap
假如JVM 无法在java heap 取得内存配置多的java objectsJVM 会丢出java out of memory 错误,JVM 无法配置多的java objects 假如heap

正在使用的objects java heap 无法再扩展。在这个况下,在丢出java.lang.OutOfMemoryError 错误讯息后,JVM 会让应用系统决定要做

么。如:应用系统自监控这个错误并且决定在那一个的模式下停止执,或者管这个错误。假如应用系统这个错误,那么thread 会丢出这个错

误讯息并且停止执行離JVM(假如使用java threaddump,你将会看到这个thread)
WebLogic Server
在这个况,假如它是由一个execute thread 丢出,这个错误将会被监控并且会做记錄。假如这是断被丢出,那么core

healthmonitor thread 会停止WebLogic Server 运作。
 
Out of Memory in native heap
假如无法native memory 配置到内存空间,则JVM 丢出native out ofmemory,这通常发生在Process 达到操作系统Process size 的限制或是机器

超出RAM Swap Space 加总.当这个发生时,JVM 会处native out memory 情况,记錄讯息明它执 out of native memory 或无法取得内存

并且开。假如JVM 或任何被加载的module(像是libc 或是一个Third party module)无法处这个native out ofmemory 况,然后操作系统将会传

送一个sigabort 讯息给JVM,这样将会使JVM 停止开。通当JVM 将会产生程序代码文件当它取得sigabort 讯号。

 

 

标签 : ,

Diagnosing java.lang.OutOfMemoryError ( 诊断Java内存溢出)

 

* Exception in thread “CompilerThread1″ java.lang.OutOfMemoryError: requested 793020 bytes for Chunk::new. Out of swap space?

Out of memory while reading in symbol table of /apps/bea/weblogic92/jdk1.5.0.18/opt/java1.5/jre/lib/PA_RISC2.0/server/libjvm.sl
( 0)  0xc8461230     [/apps/bea/weblogic92/jdk1.5.0.18/opt/java1.5/jre/lib/PA_RISC2.0/server/libjvm.sl]
( 1)  0xc80a5fec     [/apps/bea/weblogic92/jdk1.5.0.18/opt/java1.5/jre/lib/PA_RISC2.0/server/libjvm.sl]
( 2)  0xc7f00420     [/apps/bea/weblogic92/jdk1.5.0.18/opt/java1.5/jre/lib/PA_RISC2.0/server/libjvm.sl]
( 3)  0xc7f00ca0     [/apps/bea/weblogic92/jdk1.5.0.18/opt/java1.5/jre/lib/PA_RISC2.0/server/libjvm.sl]
( 4)  0xc8368d08     [/apps/bea/weblogic92/jdk1.5.0.18/opt/java1.5/jre/lib/PA_RISC2.0/server/libjvm.sl]
( 5)  0xc005b2e4   __pthread_body + 0×44  [/usr/lib/libpthread.1]
( 6)  0xc0065574   __pthread_start + 0×14  [/usr/lib/libpthread.1]
Java out of memory messages are marked with pid: 13828 in /var/adm/syslog/syslog.log.

Possible causes:
- not enough swap space left, or
- kernel parameter MAXDSIZ is very small.

Solution:
Although it appears that an OutOfMemoryError is thrown this apparent exception is reported by the HotSpot VM code when an allocation from the native heap failed and the native heap may be close to exhaustion. The message indicates the size (in bytes) of the request that failed and also indicates what the memory is required for. In some cases the reason will be shown but in most cases the reason will be the name of a source module reporting the allocation failure. If an OutOfMemoryError with this error is thrown it may require using utilities on the operating system to diagnose the issue further. Examples of issues that may not be related to the application are when the operating system is configured with insufficient swap space, or when there is another process on the system that is consuming all memory resources. If neither of these issues is the cause then it is possible that the application is failed due to native leak; for example, application or library code is continuously allocating memory but is not releasing it to the operating system.
For more information: http://java.sun.com/j2se/1.5/pdf/jdk50_ts_guide.pdf

The recommendation for swap space size in the Solaris is that swap should be configured about 30% of physical RAM.

The following link has suggested a workaround to add ‘-XX:+UseDefaultStackSize -Xss256K’ parameter.

http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4916142

Add: -XX:CodeCacheMinimumFreeSpace=2M -XX:+ReservedCodeCacheSize=64M -XX:PermSize=128m -XX:MaxPermSize=384m (As per your other JVM settings)

Sun team needs to be involved for this issue. Usually such issues are solved by sun support.

=============================

* java.lang.OutOfMemoryError: unable to create new native thread
at java.lang.Thread.start0(Native Method)
at java.lang.Thread.start(Thread.java:574)
at weblogic.work.RequestManager.createThreadAndExecute(RequestManager.java:271)
at weblogic.work.RequestManager.executeIt(RequestManager.java:245)
at weblogic.work.ServerWorkManagerImpl.schedule(ServerWorkManagerImpl.java:142)

Solution:
1) Set kernel parameter maxdsiz to a higher value
2) Reduce the current heap size.
3) Check the kernel values:  ulimit -a
4) If the NPROC soft limit is lower than the hard limit, increase it as needed: ulimit -u <new value>.
Check the Operating System documentation to make changes permanent at the OS configuration files.
5) Need to reduce the JVM stack size and the OS stack size both. Set the -xss in java options and set ulimit -s on the OS level.

=============================

* java.lang.OutOfMemoryError: PermGen space
at java.lang.Class.getDeclaredConstructors0(Native Method)
at java.lang.Class.privateGetDeclaredConstructors(Unknown Source)
at java.lang.Class.getConstructor0(Unknown Source)
at java.lang.Class.getConstructor(Unknown Source)

Solution: Increase the max permgen space -XX:MaxPermSize=256m

There can be a leak in the permgen objects. If tuning parameters do not resolve the issue, we need to use the memory leak detector tools and find out which instances in the permgen space are not getting cleared.

=============================

* java.lang.OutOfMemoryError: allocLargeObjectOrArray – Object size: 372032, Num elements: 372012
* java.lang.outofmemoryerror: nativeGetNewTLA

Solution: -XXtlasize:128k -XXlargeobjectlimit:128k

If this does not solve the issue, we need to check in the application code for the large objects being created and not being destroyed. Take JRA Recording (Oracle JRockit) or use JConsole and memory leak detector tools (JMAP, JHAT) for analysis on the

=============================

* java.lang.OutOfMemoryError: Java Heap Space

Solution: First thing that needs to be checked is the gc logs. Need to check whether the garbage collection is happening properly. If the heap keeps gradually increasing even after full gc, tune the gc algorithms and check if the behavior is the same. Use memory leak detector tools for both sun jdk and JRockit to check which instances from the application are not getting destroyed.

If this is not the case and the application genuinely needs more memory, increase the heap size by using the parameters:
Example: -Xms2048m -Xmx2048m

=============================

* java.lang.StackOverflowError

Solution: Stack over flow error is usually generated due to a recursive call made by the application (infinite recursion), or its because of an attempt to allocate more memory on the stack than will fit. This is usually the result of creating local array variables that are far too large for the current stack.

For the first possibility, we need to check the application code as to where is the recursive call being made.
For the second possibility, we can increase the JVM stack size by the parameter : Example: -Xss512K

=============================

 

标签 : ,

程序员那些悲催的事儿

在StakeOverflow上有这样一个贴子叫“Confessions of your worst WTF moment”(WTF就是What the fuck的缩写),挺有意思的,我摘几个小故事过来,希望大家在笑过之后能从中学到什么——所有的经验都是从错误中来的

阅读全文……

标签 : ,

MocoSpace网站的架构

 

MocoSpace.com 是一家移动社交网站,有1200多万注册用户,每个月30亿的 PV ,是美国最大的移动社区。我们来看看 MocoSpace 是如何来架构他们的网站的。先来看看他们的统计数据,注意他们只有1个系统管理员,8个程序员,14台服务器(数据和原文来自  MOCOSPACE ARCHITECTURE – 3 BILLION MOBILE PAGE VIEWS A MONTH):

数据

每月30亿 PV 
全美第4大流量的网站,继 MySpace, Facebook, Google 之后 
75% 手机 Web, 25% Web 
1200 万用户 
每月600万独立访问 
10万在线用户 
每月上传1200万照片 
每天接受和发送450万 email 
8个程序员,2个测试员,1个系统管理员

平台和工具

CentOS + Red Hat 
Resin application server, Java Servlets, JavaServer Pages, Comet 
PostgreSQL 
Memcached 
ActiveMQ’s job + message queue,Red Hat 集群做 HA 
Squid 静态内容缓存,曾试过 Varnish 但是 Varnish 不稳定 
JQuery + Ajax 
S3 用来存储用户照片和视频,现在用 Amazon S3 做外部存储是主流,EC2 用来做照片处理 
F5 BigIP 负载均衡,用 gzip 压缩所有页面 
Akamai CDN,每天 2TB 数据、2.5亿次请求。 
Nagios 用来警告,Zabbix 用来监测 
EMC SAN 用大量磁盘做 RAID 10 做需要高 IO 的数据库存储,用来替代高性能的 SSD,节省了大量成本 
PowerMTA 做邮件传送,用Barracuda 做 spam 和 firewall 
Subversion 做源代码控制,Hudson 做 continuous integration 
FFMPEG 用来做视频处理 
Selenium 用来自动测试浏览器 
5x Dell 1950, 2x dual core, 16G RAM(Web 服务器) 
5x Dell 6950/R905, 4x dual core, 32G RAM(Web 服务器) 
2x Sun Fire X4600 M2 Server, 8x quad core, 256G RAM(数据库服务器) 
2x Dell 6950, 4x dual core, 64G RAM(数据库服务器)

 

阅读全文……

标签 :

Spring Component-scan和eclipse export jar兼容问题

Spring使用component-scan的时候,如果把spring bean打包到jar文件中,spring无法找到相应的bean

要处理正确很简单:当使用eclipse export成.jar的时候,把add directory entries选上就可以了

或者使用下列打包方法:

jar cvf jj.jar com META-INF jdbc.properties beans.xml

标签 : , ,

Oracle VirtualBox VErr_DISK_fULL Problem

Well I bet you have a FAT 32 format on the drive and are trying to put a file bigger than 4 gig on it. Convert to NTFS.

 

标签 : ,

Using POSTGIS to find points of interest within a radius(用postgis搜索某点半径内POI点)

I've recently looked into using PostGIS, an extension that enables support for spatial objects in PostgresSQL database.

The problem I was trying to solve is, given a point with (longitude, latitude), how can I find all other points within a certain radius. I've solved it before using formula to calculate distances between 2 points but it's pretty slow if your table has a lot of records. PostGIS can help solve this problem faster and more elegant. 

First thing first, let's get us some data to play around with. I found this excellent tutorial that teaches you how to get zipcode data from the US Census. I'll skim through it here, but you should definitely check out that article.

Assume you have a zipcode table with these columns:


state zip latitude longitude
-------------------------------------------
CA 92230 33.911404 -116.768347
CA 92234 33.807761 -116.464731
CA 92236 33.679872 -116.176562


Now you need to add a column to this table to hold the geometric data represents by [longitude, latitude] pair. 

SELECT AddGeometryColumn( 'public', 'zipcode', 'geom', 32661, 'POINT', 2 );

* add column 'geom' into table 'zipcode' under schema 'public'
* the column holds a point with 2 dimensions and has spherical reference id (srid) 32661

* now we populate the table with data converted from srid 4269 (longitude/latitude measurement) to srid 32661 (WGS 84 system)

UPDATE zipcode
SET geom = transform(PointFromText('POINT(' || longitude || ' ' || latitude || ')',4269),32661) ;

The transformation from one spherical reference to another is needed for calculating the surface distance.WGS84 is measured in meters by the way.

Now your table will look like this


state zip latitude longitude geom
-----------------------------------------------
CA 92230 33.911404 -116.768347 0101000020957F0000B7FB4ED5F2C44EC166AFB20D1A3D5341
CA 92234 33.807761 -116.464731 0101000020957F0000AA8102ECECFD4EC18284302439245341
CA 92236 33.679872 -116.176562 0101000020957F000067A4B44D2D3B4FC1596E974B370E5341


Now we only need to write a query, say, find me all the zipcode within 10 mile radius of "92230". (or 16093 meters)


SELECT state, zip
FROM zipcode
WHERE
distance(
   transform(PointFromText('POINT(-116.768347 33.911404)', 4269),32661),
   geom) < 16093


Here function distance(here_geom, there_geom) returns meters. Notice how you would read in a point(long/lat) from string using PointFromText() then do the transform.

However, this query isn't optimal. It calculates distances from zip 92230 to all other zipcodes. We would rather have a bounding box of 10 miles around our interested point, filtering out the points that interact with this box then calculate the exact distances to the center. Sounds like a lot of work but in reality, it can be achieve by adding another condition:


SELECT state, zip
FROM zipcode
WHERE
geom && expand(transform(PointFromText('POINT(-116.768347 33.911404)', 4269),32661), 16093)
AND
distance(
   transform(PointFromText('POINT(-116.768347 33.911404)', 4269),32661),
   geom) < 16093



The new query is much much faster. My benchmark shows 200% in speed compared to the first query. Pretty sweet!

 

标签 : ,