dongxun7962 2015-01-15 08:13
浏览 30

为什么在Web应用程序中进行垃圾收集?

Consider building a web app on a platform where every request is handled by a User Level Thread(ULT) (green thread/erlang process/goroutine/... any light weight thread). Assuming every request is stateless and resources like DB connection are obtained at startup of the app and shared between these threads. What is the need for garbage collection in these threads?

Generally such a thread is short running(a few milliseconds) and if well designed doesn't use more than a few (KB or MB) of memory. If garbage collection of the resources allocated in the thread is done at the exit of the thread and independent of the other threads, then there would be no GC pauses for even the 98th or 99th percentile of requests. All requests would be answered in predictable time.

What is the problem with such a model and why is it not being widely used?

  • 写回答

1条回答 默认 最新

  • douhuang5623 2015-01-15 08:56
    关注

    You assumption might not be true.

    if well designed doesn't use more than a few (KB or MB) of memory

    Imagine a function for counting words in a text file which is used in a web app. Some naive implementation could be,

    def count_words(text):
        words = text.split()
        count = {}
        for w in words:
            if w in count:
                count[w] += 1
            else:
                count[w] = 1
        return count
    

    It allocates larger memory than text.

    评论

报告相同问题?

悬赏问题

  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥15 想问一下树莓派接上显示屏后出现如图所示画面,是什么问题导致的
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化