亚洲av成人无遮挡网站在线观看,少妇性bbb搡bbb爽爽爽,亚洲av日韩精品久久久久久,兔费看少妇性l交大片免费,无码少妇一区二区三区

  免費(fèi)注冊(cè) 查看新帖 |

Chinaunix

  平臺(tái) 論壇 博客 文庫(kù)
最近訪問(wèn)板塊 發(fā)新帖
查看: 2477 | 回復(fù): 3
打印 上一主題 下一主題

[函數(shù)] 【mnesia】分片 [復(fù)制鏈接]

論壇徽章:
30
水瓶座
日期:2014-08-22 21:06:3415-16賽季CBA聯(lián)賽之新疆
日期:2015-12-19 19:05:48IT運(yùn)維版塊每日發(fā)帖之星
日期:2015-12-25 06:20:31IT運(yùn)維版塊每日發(fā)帖之星
日期:2015-12-25 06:20:31IT運(yùn)維版塊每日發(fā)帖之星
日期:2015-12-25 06:20:3315-16賽季CBA聯(lián)賽之上海
日期:2016-04-15 19:51:31程序設(shè)計(jì)版塊每日發(fā)帖之星
日期:2016-04-17 06:23:29程序設(shè)計(jì)版塊每日發(fā)帖之星
日期:2016-04-23 06:20:00程序設(shè)計(jì)版塊每日發(fā)帖之星
日期:2016-05-26 06:20:00每日論壇發(fā)貼之星
日期:2016-05-26 06:20:0015-16賽季CBA聯(lián)賽之遼寧
日期:2017-02-16 23:59:4715-16賽季CBA聯(lián)賽之天津
日期:2019-01-11 01:11:44
跳轉(zhuǎn)到指定樓層
1 [收藏(0)] [報(bào)告]
發(fā)表于 2015-02-03 23:01 |只看該作者 |倒序?yàn)g覽
在其它數(shù)據(jù)庫(kù)里也有分片的概念,原因是有大表,我這里有一個(gè)例子,數(shù)據(jù)是全球ip地址信息到城市,數(shù)據(jù)大約是460萬(wàn),全load到內(nèi)存我的筆記本6G,撐不住。用了分片(10)后,內(nèi)存也占用不少,但是不至于load不起來(lái)。

論壇徽章:
30
水瓶座
日期:2014-08-22 21:06:3415-16賽季CBA聯(lián)賽之新疆
日期:2015-12-19 19:05:48IT運(yùn)維版塊每日發(fā)帖之星
日期:2015-12-25 06:20:31IT運(yùn)維版塊每日發(fā)帖之星
日期:2015-12-25 06:20:31IT運(yùn)維版塊每日發(fā)帖之星
日期:2015-12-25 06:20:3315-16賽季CBA聯(lián)賽之上海
日期:2016-04-15 19:51:31程序設(shè)計(jì)版塊每日發(fā)帖之星
日期:2016-04-17 06:23:29程序設(shè)計(jì)版塊每日發(fā)帖之星
日期:2016-04-23 06:20:00程序設(shè)計(jì)版塊每日發(fā)帖之星
日期:2016-05-26 06:20:00每日論壇發(fā)貼之星
日期:2016-05-26 06:20:0015-16賽季CBA聯(lián)賽之遼寧
日期:2017-02-16 23:59:4715-16賽季CBA聯(lián)賽之天津
日期:2019-01-11 01:11:44
2 [報(bào)告]
發(fā)表于 2015-02-03 23:01 |只看該作者
  1. -module(location).
  2. -include_lib("include/location.hrl").
  3. -include_lib("stdlib/include/qlc.hrl").
  4. -compile(export_all).

  5. read_txt() ->
  6.     {ok, M} = file:open("dbip-city.csv", [binary, read]),
  7.     read_line(M).

  8. read_line(M) ->
  9.     case file:read_line(M) of
  10.       {ok, L} -> i(L), read_line(M);
  11.       {eof} -> ok, file:close(M)
  12.     end.

  13. i(S) ->
  14.     Slash = binary:replace(S, <<"\"">>, <<>>, [global]),
  15.     T = erlang:binary_to_list(Slash),
  16.     R = string:tokens(T, "\n"),
  17.     spawn(fun () -> insert_data(R) end).

  18. insert_data(L) ->
  19.     case string:tokens(lists:flatten(L), ",") of
  20.       [Ip, Mask, Country, Area0, Area1, Area2] ->
  21.           Row = #location{ip = Ip, mask = Mask, country = Country,
  22.                           area = Area0, city = lists:concat([Area1, Area2])};
  23.       [Ip, Mask, Country, Area, City] ->
  24.           Row = #location{ip = Ip, mask = Mask, country = Country,
  25.                           area = Area, city = City};
  26.       [Ip, Mask, Country, Area] ->
  27.           Row = #location{ip = Ip, mask = Mask, country = Country,
  28.                           area = Area};
  29.       [Ip, Mask, Country] ->
  30.           Row = #location{ip = Ip, mask = Mask, country = Country}
  31.     end,
  32.     db_dirty_write(Row).

  33. init_table() ->
  34.     mnesia:start(),
  35.     mnesia:delete_table(location),
  36.     mnesia:create_table(location,
  37.                         [{attributes, record_info(fields, location)},
  38.                          {disc_only_copies, [node()]}]),
  39.     mnesia:change_config(extra_db_nodes, [b]),
  40.     mnesia:add_table_copy(location, nodes(),
  41.                           disc_only_copies),
  42.     read_txt().

  43. address(Ip) ->
  44.     MatchHead = #location{ip = '$4', mask = '$5',
  45.                           country = '$1', area = '$2', city = '$3'},
  46.     Guard = [{'>=', '$4', Ip}, {'=<', '$5', Ip}],
  47.     Result = ['$4', '$5', '$1', '$2', '$3'],
  48.     MatchSpec = [{MatchHead, Guard, Result}],
  49.     SelFun = fun () ->
  50.                      mnesia:select(location, MatchSpec, 10, read)
  51.              end,
  52.     mnesia:activity(transaction, SelFun, [], mnesia_frag).

  53. query(Ip) ->
  54.     Query = fun () ->
  55.                     Q = qlc:q([E
  56.                                || E <- mnesia:table(location),
  57.                                   E#location.ip =< Ip]),
  58.                     Sort = qlc:e(qlc:keysort(2, Q, [{order, descending}])),
  59.                     QC = qlc:cursor(Sort),
  60.                     qlc:next_answers(QC, 1)
  61.             end,
  62.     {atomic, Results} = mnesia:transaction(Query),
  63.     Results.

  64. q(Ip) ->
  65.     Query = fun () ->
  66.                     qlc:eval(qlc:q([[E#location.ip, E#location.mask,
  67.                                      E#location.country, E#location.area,
  68.                                      E#location.city]
  69.                                     || E <- mnesia:table(location),
  70.                                        (Ip =< E#location.mask) and
  71.                                          (E#location.ip =< Ip)]))
  72.             end,
  73.     {atomic, Results} = mnesia:transaction(Query),
  74.     Results.

  75. q1() -> mnesia:dirty_read({location, "195.101.114.0"}).

  76. q2() ->
  77.     mnesia:match_object({location, "195.101.114.0"}).

  78. db() ->
  79.     mnesia:create_table(location,
  80.                         [{frag_properties,
  81.                           [{n_fragments, 20}, {n_disc_copies, 1},
  82.                            {node_pool, [node()]}]},
  83.                          %{index, [ip, mask, country,area]},
  84.                          {attributes, record_info(fields, location)}]).

  85. db_dirty_write(Row) ->
  86.     AddFun = fun () -> mnesia:write(location, Row, write)
  87.              end,
  88.     ok = mnesia:activity(async_dirty, AddFun, [],
  89.                          mnesia_frag).
復(fù)制代碼

論壇徽章:
30
水瓶座
日期:2014-08-22 21:06:3415-16賽季CBA聯(lián)賽之新疆
日期:2015-12-19 19:05:48IT運(yùn)維版塊每日發(fā)帖之星
日期:2015-12-25 06:20:31IT運(yùn)維版塊每日發(fā)帖之星
日期:2015-12-25 06:20:31IT運(yùn)維版塊每日發(fā)帖之星
日期:2015-12-25 06:20:3315-16賽季CBA聯(lián)賽之上海
日期:2016-04-15 19:51:31程序設(shè)計(jì)版塊每日發(fā)帖之星
日期:2016-04-17 06:23:29程序設(shè)計(jì)版塊每日發(fā)帖之星
日期:2016-04-23 06:20:00程序設(shè)計(jì)版塊每日發(fā)帖之星
日期:2016-05-26 06:20:00每日論壇發(fā)貼之星
日期:2016-05-26 06:20:0015-16賽季CBA聯(lián)賽之遼寧
日期:2017-02-16 23:59:4715-16賽季CBA聯(lián)賽之天津
日期:2019-01-11 01:11:44
3 [報(bào)告]
發(fā)表于 2015-02-03 23:02 |只看該作者
用這種數(shù)據(jù)學(xué)習(xí)mnesia我覺得是個(gè)好的方法。

論壇徽章:
30
水瓶座
日期:2014-08-22 21:06:3415-16賽季CBA聯(lián)賽之新疆
日期:2015-12-19 19:05:48IT運(yùn)維版塊每日發(fā)帖之星
日期:2015-12-25 06:20:31IT運(yùn)維版塊每日發(fā)帖之星
日期:2015-12-25 06:20:31IT運(yùn)維版塊每日發(fā)帖之星
日期:2015-12-25 06:20:3315-16賽季CBA聯(lián)賽之上海
日期:2016-04-15 19:51:31程序設(shè)計(jì)版塊每日發(fā)帖之星
日期:2016-04-17 06:23:29程序設(shè)計(jì)版塊每日發(fā)帖之星
日期:2016-04-23 06:20:00程序設(shè)計(jì)版塊每日發(fā)帖之星
日期:2016-05-26 06:20:00每日論壇發(fā)貼之星
日期:2016-05-26 06:20:0015-16賽季CBA聯(lián)賽之遼寧
日期:2017-02-16 23:59:4715-16賽季CBA聯(lián)賽之天津
日期:2019-01-11 01:11:44
4 [報(bào)告]
發(fā)表于 2015-02-03 23:03 |只看該作者
你可以下載到數(shù)據(jù) https://db-ip.com/db/#php 第二列IP address to city (low resolution)
您需要登錄后才可以回帖 登錄 | 注冊(cè)

本版積分規(guī)則 發(fā)表回復(fù)

  

北京盛拓優(yōu)訊信息技術(shù)有限公司. 版權(quán)所有 京ICP備16024965號(hào)-6 北京市公安局海淀分局網(wǎng)監(jiān)中心備案編號(hào):11010802020122 niuxiaotong@pcpop.com 17352615567
未成年舉報(bào)專區(qū)
中國(guó)互聯(lián)網(wǎng)協(xié)會(huì)會(huì)員  聯(lián)系我們:huangweiwei@itpub.net
感謝所有關(guān)心和支持過(guò)ChinaUnix的朋友們 轉(zhuǎn)載本站內(nèi)容請(qǐng)注明原作者名及出處

清除 Cookies - ChinaUnix - Archiver - WAP - TOP